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:
@@ -12,6 +12,7 @@ import (
|
||||
"runtime"
|
||||
"strings"
|
||||
|
||||
"github.com/steveyegge/beads/internal/git"
|
||||
"github.com/steveyegge/beads/internal/storage"
|
||||
"github.com/steveyegge/beads/internal/syncbranch"
|
||||
"github.com/steveyegge/beads/internal/types"
|
||||
@@ -199,6 +200,22 @@ func findBeadsDir() string {
|
||||
return ""
|
||||
}
|
||||
|
||||
// Check if we're in a git worktree with sparse checkout
|
||||
// In worktrees, .beads might not exist locally, so we need to resolve to the main repo
|
||||
if git.IsWorktree() {
|
||||
mainRepoRoot, err := git.GetMainRepoRoot()
|
||||
if err == nil && mainRepoRoot != "" {
|
||||
mainBeadsDir := filepath.Join(mainRepoRoot, ".beads")
|
||||
if info, err := os.Stat(mainBeadsDir); err == nil && info.IsDir() {
|
||||
resolved, err := filepath.EvalSymlinks(mainBeadsDir)
|
||||
if err != nil {
|
||||
return mainBeadsDir
|
||||
}
|
||||
return resolved
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
for {
|
||||
beadsDir := filepath.Join(dir, ".beads")
|
||||
if info, err := os.Stat(beadsDir); err == nil && info.IsDir() {
|
||||
|
||||
Reference in New Issue
Block a user