feat: allow local repo reference clones to save disk
Use git --reference-if-able when a local repo is provided so rigs and crew share objects without changing remotes. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
@@ -40,6 +40,12 @@ func (g *Git) WorkDir() string {
|
||||
return g.workDir
|
||||
}
|
||||
|
||||
// IsRepo returns true if the workDir is a git repository.
|
||||
func (g *Git) IsRepo() bool {
|
||||
_, err := g.run("rev-parse", "--git-dir")
|
||||
return err == nil
|
||||
}
|
||||
|
||||
// run executes a git command and returns stdout.
|
||||
func (g *Git) run(args ...string) (string, error) {
|
||||
// If gitDir is set (bare repo), prepend --git-dir flag
|
||||
@@ -99,6 +105,18 @@ func (g *Git) Clone(url, dest string) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
// CloneWithReference clones a repository using a local repo as an object reference.
|
||||
// This saves disk by sharing objects without changing remotes.
|
||||
func (g *Git) CloneWithReference(url, dest, reference string) error {
|
||||
cmd := exec.Command("git", "clone", "--reference-if-able", reference, url, dest)
|
||||
var stderr bytes.Buffer
|
||||
cmd.Stderr = &stderr
|
||||
if err := cmd.Run(); err != nil {
|
||||
return g.wrapError(err, stderr.String(), []string{"clone", "--reference-if-able", url})
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// CloneBare clones a repository as a bare repo (no working directory).
|
||||
// This is used for the shared repo architecture where all worktrees share a single git database.
|
||||
func (g *Git) CloneBare(url, dest string) error {
|
||||
@@ -111,6 +129,17 @@ func (g *Git) CloneBare(url, dest string) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
// CloneBareWithReference clones a bare repository using a local repo as an object reference.
|
||||
func (g *Git) CloneBareWithReference(url, dest, reference string) error {
|
||||
cmd := exec.Command("git", "clone", "--bare", "--reference-if-able", reference, url, dest)
|
||||
var stderr bytes.Buffer
|
||||
cmd.Stderr = &stderr
|
||||
if err := cmd.Run(); err != nil {
|
||||
return g.wrapError(err, stderr.String(), []string{"clone", "--bare", "--reference-if-able", url})
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// Checkout checks out the given ref.
|
||||
func (g *Git) Checkout(ref string) error {
|
||||
_, err := g.run("checkout", ref)
|
||||
|
||||
Reference in New Issue
Block a user