diff --git a/internal/git/git.go b/internal/git/git.go index 226664b9..a207bce0 100644 --- a/internal/git/git.go +++ b/internal/git/git.go @@ -266,6 +266,8 @@ func (g *Git) Clone(url, dest string) error { if err := configureHooksPath(dest); err != nil { return err } + // Enable parallel checkout for faster worktree operations + _ = configureParallelCheckout(dest) // Configure sparse checkout to exclude .claude/ from source repo return ConfigureSparseCheckout(dest) } @@ -306,6 +308,8 @@ func (g *Git) CloneWithReference(url, dest, reference string) error { if err := configureHooksPath(dest); err != nil { return err } + // Enable parallel checkout for faster worktree operations + _ = configureParallelCheckout(dest) // Configure sparse checkout to exclude .claude/ from source repo return ConfigureSparseCheckout(dest) } @@ -342,10 +346,27 @@ func (g *Git) CloneBare(url, dest string) error { return fmt.Errorf("moving clone to destination: %w", err) } + // Enable parallel checkout for faster worktree operations + _ = configureParallelCheckout(dest) // Configure refspec so worktrees can fetch and see origin/* refs return configureRefspec(dest) } +// configureParallelCheckout enables parallel checkout workers for faster file operations. +// Git 2.33+ supports checkout.workers which parallelizes file creation during checkout, +// significantly speeding up worktree creation and clone operations. +func configureParallelCheckout(repoPath string) error { + // Enable parallel checkout with automatic worker count (uses all CPUs) + cmd := exec.Command("git", "-C", repoPath, "config", "checkout.workers", "0") + var stderr bytes.Buffer + cmd.Stderr = &stderr + if err := cmd.Run(); err != nil { + // Non-fatal: older git versions don't support this + return nil + } + return nil +} + // configureHooksPath sets core.hooksPath to use the repo's .githooks directory // if it exists. This ensures Gas Town agents use the pre-push hook that blocks // pushes to non-main branches (internal PRs are not allowed). @@ -424,6 +445,8 @@ func (g *Git) CloneBareWithReference(url, dest, reference string) error { return fmt.Errorf("moving clone to destination: %w", err) } + // Enable parallel checkout for faster worktree operations + _ = configureParallelCheckout(dest) // Configure refspec so worktrees can fetch and see origin/* refs return configureRefspec(dest) } @@ -483,10 +506,10 @@ func (g *Git) CommitAll(message string) error { // GitStatus represents the status of the working directory. type GitStatus struct { - Clean bool - Modified []string - Added []string - Deleted []string + Clean bool + Modified []string + Added []string + Deleted []string Untracked []string } @@ -1208,8 +1231,8 @@ type UncommittedWorkStatus struct { StashCount int UnpushedCommits int // Details for error messages - ModifiedFiles []string - UntrackedFiles []string + ModifiedFiles []string + UntrackedFiles []string } // Clean returns true if there is no uncommitted work.