diff --git a/pkg/repos/get.go b/pkg/repos/get.go index 43c7e160..db96dc8a 100644 --- a/pkg/repos/get.go +++ b/pkg/repos/get.go @@ -9,6 +9,7 @@ import ( "os" "path/filepath" + "github.com/BurntSushi/locker" "github.com/gptscript-ai/gptscript/pkg/repos/git" "github.com/gptscript-ai/gptscript/pkg/types" ) @@ -52,6 +53,9 @@ func New(cacheDir string, runtimes ...Runtime) *Manager { } func (m *Manager) setup(ctx context.Context, runtime Runtime, tool types.Tool, env []string) (string, []string, error) { + locker.Lock(tool.ID) + defer locker.Unlock(tool.ID) + target := filepath.Join(m.storageDir, tool.Source.Repo.Revision, runtime.ID()) targetFinal := filepath.Join(target, tool.Source.Repo.Path) doneFile := target + ".done" diff --git a/pkg/repos/git/cmd.go b/pkg/repos/git/cmd.go index 2f724a55..7bbf0ecb 100644 --- a/pkg/repos/git/cmd.go +++ b/pkg/repos/git/cmd.go @@ -19,7 +19,8 @@ func cloneBare(ctx context.Context, repo, toDir string) error { } func gitWorktreeAdd(ctx context.Context, gitDir, commitDir, commit string) error { - cmd := newGitCommand(ctx, "--git-dir", gitDir, "worktree", "add", "-f", commitDir, commit) + // The double -f is intentional + cmd := newGitCommand(ctx, "--git-dir", gitDir, "worktree", "add", "-f", "-f", commitDir, commit) return cmd.Run() }