feat: add Git worktree compatibility (PR #478)

Adds comprehensive Git worktree support for beads issue tracking:

Core changes:
- New internal/git/gitdir.go package for worktree detection
- GetGitDir() returns proper .git location (main repo, not worktree)
- Updated all hooks to use git.GetGitDir() instead of local helper
- BeadsDir() now prioritizes main repository's .beads directory

Features:
- Hooks auto-install in main repo when run from worktree
- Shared .beads directory across all worktrees
- Config option no-install-hooks to disable auto-install
- New bd worktree subcommand for diagnostics

Documentation:
- New docs/WORKTREES.md with setup instructions
- Updated CHANGELOG.md and AGENT_INSTRUCTIONS.md

Testing:
- Updated tests to use exported git.GetGitDir()
- Added worktree detection tests

Co-authored-by: Claude <noreply@anthropic.com>
Closes: #478
This commit is contained in:
matt wilkie
2025-12-13 10:40:40 -08:00
committed by Steve Yegge
parent de7b511765
commit e01b7412d9
64 changed files with 1895 additions and 3708 deletions

View File

@@ -44,14 +44,20 @@ func syncBranchCommitAndPushWithOptions(ctx context.Context, store storage.Stora
log.log("Using sync branch: %s", syncBranch)
// Get repo root
repoRoot, err := getGitRoot(ctx)
// Get main repo root (for worktrees, this is the main repo, not worktree)
repoRoot, err := git.GetMainRepoRoot()
if err != nil {
return false, fmt.Errorf("failed to get git root: %w", err)
return false, fmt.Errorf("failed to get main repo root: %w", err)
}
// Use worktree-aware git directory detection
gitDir, err := git.GetGitDir()
if err != nil {
return false, fmt.Errorf("not a git repository: %w", err)
}
// Worktree path is under .git/beads-worktrees/<branch>
worktreePath := filepath.Join(repoRoot, ".git", "beads-worktrees", syncBranch)
worktreePath := filepath.Join(gitDir, "beads-worktrees", syncBranch)
// Initialize worktree manager
wtMgr := git.NewWorktreeManager(repoRoot)
@@ -216,14 +222,20 @@ func syncBranchPull(ctx context.Context, store storage.Storage, log daemonLogger
return false, nil
}
// Get repo root
repoRoot, err := getGitRoot(ctx)
// Get main repo root (for worktrees, this is the main repo, not worktree)
repoRoot, err := git.GetMainRepoRoot()
if err != nil {
return false, fmt.Errorf("failed to get git root: %w", err)
return false, fmt.Errorf("failed to get main repo root: %w", err)
}
// Use worktree-aware git directory detection
gitDir, err := git.GetGitDir()
if err != nil {
return false, fmt.Errorf("not a git repository: %w", err)
}
// Worktree path is under .git/beads-worktrees/<branch>
worktreePath := filepath.Join(repoRoot, ".git", "beads-worktrees", syncBranch)
worktreePath := filepath.Join(gitDir, "beads-worktrees", syncBranch)
// Initialize worktree manager
wtMgr := git.NewWorktreeManager(repoRoot)