From 1f364ee5409f6fad4027deb7ebfea536507ef05d Mon Sep 17 00:00:00 2001 From: slit Date: Mon, 26 Jan 2026 12:27:42 -0800 Subject: [PATCH] perf(git): enable parallel checkout for faster worktree creation Configure checkout.workers=0 (auto-detect CPU count) on all clone operations. Git 2.33+ supports this feature which parallelizes file creation during checkout, significantly speeding up worktree creation. This is applied to: - Clone() - regular clones - CloneWithReference() - clones with local reference - CloneBare() - bare clones (primary source for worktrees) - CloneBareWithReference() - bare clones with reference The config is set per-repo so worktrees inherit it automatically. Older git versions silently ignore this config (non-fatal). Recovered from: 4ed3e983 (lost commit) --- internal/git/git.go | 35 +++++++++++++++++++++++++++++------ 1 file changed, 29 insertions(+), 6 deletions(-) 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.