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:
@@ -65,11 +65,6 @@ func InstallClaude(project bool, stealth bool) {
|
||||
fmt.Println("✓ Registered PreCompact hook")
|
||||
}
|
||||
|
||||
// Add bd to allowedTools so commands don't require per-command approval
|
||||
if addAllowedTool(settings, "Bash(bd *)") {
|
||||
fmt.Println("✓ Added bd to allowedTools (no per-command approval needed)")
|
||||
}
|
||||
|
||||
// Write back to file
|
||||
data, err = json.MarshalIndent(settings, "", " ")
|
||||
if err != nil {
|
||||
@@ -154,9 +149,6 @@ func RemoveClaude(project bool) {
|
||||
removeHookCommand(hooks, "SessionStart", "bd prime --stealth")
|
||||
removeHookCommand(hooks, "PreCompact", "bd prime --stealth")
|
||||
|
||||
// Remove bd from allowedTools
|
||||
removeAllowedTool(settings, "Bash(bd *)")
|
||||
|
||||
// Write back
|
||||
data, err = json.MarshalIndent(settings, "", " ")
|
||||
if err != nil {
|
||||
@@ -172,49 +164,6 @@ func RemoveClaude(project bool) {
|
||||
fmt.Println("✓ Claude hooks removed")
|
||||
}
|
||||
|
||||
// addAllowedTool adds a tool pattern to allowedTools if not already present
|
||||
// Returns true if tool was added, false if already exists
|
||||
func addAllowedTool(settings map[string]interface{}, tool string) bool {
|
||||
// Get or create allowedTools array
|
||||
allowedTools, ok := settings["allowedTools"].([]interface{})
|
||||
if !ok {
|
||||
allowedTools = []interface{}{}
|
||||
}
|
||||
|
||||
// Check if tool already in list
|
||||
for _, t := range allowedTools {
|
||||
if t == tool {
|
||||
fmt.Printf("✓ Tool already in allowedTools: %s\n", tool)
|
||||
return false
|
||||
}
|
||||
}
|
||||
|
||||
// Add tool to array
|
||||
allowedTools = append(allowedTools, tool)
|
||||
settings["allowedTools"] = allowedTools
|
||||
return true
|
||||
}
|
||||
|
||||
// removeAllowedTool removes a tool pattern from allowedTools
|
||||
func removeAllowedTool(settings map[string]interface{}, tool string) {
|
||||
allowedTools, ok := settings["allowedTools"].([]interface{})
|
||||
if !ok {
|
||||
return
|
||||
}
|
||||
|
||||
// Filter out the tool
|
||||
var filtered []interface{}
|
||||
for _, t := range allowedTools {
|
||||
if t != tool {
|
||||
filtered = append(filtered, t)
|
||||
} else {
|
||||
fmt.Printf("✓ Removed %s from allowedTools\n", tool)
|
||||
}
|
||||
}
|
||||
|
||||
settings["allowedTools"] = filtered
|
||||
}
|
||||
|
||||
// addHookCommand adds a hook command to an event if not already present
|
||||
// Returns true if hook was added, false if already exists
|
||||
func addHookCommand(hooks map[string]interface{}, event, command string) bool {
|
||||
|
||||
@@ -406,135 +406,3 @@ func TestIdempotencyWithStealth(t *testing.T) {
|
||||
t.Errorf("Expected 'bd prime --stealth', got %v", cmdMap["command"])
|
||||
}
|
||||
}
|
||||
|
||||
func TestAddAllowedTool(t *testing.T) {
|
||||
tests := []struct {
|
||||
name string
|
||||
existingSettings map[string]interface{}
|
||||
tool string
|
||||
wantAdded bool
|
||||
wantLen int
|
||||
}{
|
||||
{
|
||||
name: "add tool to empty settings",
|
||||
existingSettings: make(map[string]interface{}),
|
||||
tool: "Bash(bd *)",
|
||||
wantAdded: true,
|
||||
wantLen: 1,
|
||||
},
|
||||
{
|
||||
name: "add tool to existing allowedTools",
|
||||
existingSettings: map[string]interface{}{
|
||||
"allowedTools": []interface{}{"Bash(git *)"},
|
||||
},
|
||||
tool: "Bash(bd *)",
|
||||
wantAdded: true,
|
||||
wantLen: 2,
|
||||
},
|
||||
{
|
||||
name: "tool already exists",
|
||||
existingSettings: map[string]interface{}{
|
||||
"allowedTools": []interface{}{"Bash(bd *)"},
|
||||
},
|
||||
tool: "Bash(bd *)",
|
||||
wantAdded: false,
|
||||
wantLen: 1,
|
||||
},
|
||||
}
|
||||
|
||||
for _, tt := range tests {
|
||||
t.Run(tt.name, func(t *testing.T) {
|
||||
got := addAllowedTool(tt.existingSettings, tt.tool)
|
||||
if got != tt.wantAdded {
|
||||
t.Errorf("addAllowedTool() = %v, want %v", got, tt.wantAdded)
|
||||
}
|
||||
|
||||
allowedTools, ok := tt.existingSettings["allowedTools"].([]interface{})
|
||||
if !ok {
|
||||
t.Fatal("allowedTools not found")
|
||||
}
|
||||
|
||||
if len(allowedTools) != tt.wantLen {
|
||||
t.Errorf("Expected %d tools, got %d", tt.wantLen, len(allowedTools))
|
||||
}
|
||||
|
||||
// Verify tool exists in list
|
||||
found := false
|
||||
for _, tool := range allowedTools {
|
||||
if tool == tt.tool {
|
||||
found = true
|
||||
break
|
||||
}
|
||||
}
|
||||
if !found {
|
||||
t.Errorf("Tool %q not found in allowedTools", tt.tool)
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
func TestRemoveAllowedTool(t *testing.T) {
|
||||
tests := []struct {
|
||||
name string
|
||||
existingSettings map[string]interface{}
|
||||
tool string
|
||||
wantLen int
|
||||
}{
|
||||
{
|
||||
name: "remove only tool",
|
||||
existingSettings: map[string]interface{}{
|
||||
"allowedTools": []interface{}{"Bash(bd *)"},
|
||||
},
|
||||
tool: "Bash(bd *)",
|
||||
wantLen: 0,
|
||||
},
|
||||
{
|
||||
name: "remove one of multiple tools",
|
||||
existingSettings: map[string]interface{}{
|
||||
"allowedTools": []interface{}{"Bash(git *)", "Bash(bd *)", "Bash(npm *)"},
|
||||
},
|
||||
tool: "Bash(bd *)",
|
||||
wantLen: 2,
|
||||
},
|
||||
{
|
||||
name: "remove non-existent tool",
|
||||
existingSettings: map[string]interface{}{
|
||||
"allowedTools": []interface{}{"Bash(git *)"},
|
||||
},
|
||||
tool: "Bash(bd *)",
|
||||
wantLen: 1,
|
||||
},
|
||||
{
|
||||
name: "remove from empty settings",
|
||||
existingSettings: make(map[string]interface{}),
|
||||
tool: "Bash(bd *)",
|
||||
wantLen: 0,
|
||||
},
|
||||
}
|
||||
|
||||
for _, tt := range tests {
|
||||
t.Run(tt.name, func(t *testing.T) {
|
||||
removeAllowedTool(tt.existingSettings, tt.tool)
|
||||
|
||||
allowedTools, ok := tt.existingSettings["allowedTools"].([]interface{})
|
||||
if !ok {
|
||||
// If allowedTools doesn't exist, treat as empty
|
||||
if tt.wantLen != 0 {
|
||||
t.Errorf("Expected %d tools, got 0 (allowedTools not found)", tt.wantLen)
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
if len(allowedTools) != tt.wantLen {
|
||||
t.Errorf("Expected %d remaining tools, got %d", tt.wantLen, len(allowedTools))
|
||||
}
|
||||
|
||||
// Verify tool is actually gone
|
||||
for _, tool := range allowedTools {
|
||||
if tool == tt.tool {
|
||||
t.Errorf("Tool %q still present after removal", tt.tool)
|
||||
}
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user