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)
This commit is contained in:
slit
2026-01-26 12:27:42 -08:00
committed by John Ogle
parent afdadc77ff
commit 1f364ee540

View File

@@ -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.