fix(worktree): resolve worktrees by name from git registry (#921)

This commit is contained in:
aaron-sangster
2026-01-07 02:45:27 +00:00
committed by GitHub
parent c43682f5b6
commit cca2016376
2 changed files with 121 additions and 0 deletions

View File

@@ -523,6 +523,24 @@ func resolveWorktreePath(repoRoot, name string) (string, error) {
return repoPath, nil
}
// Consult git's worktree registry - match by name (basename) or path
// This handles worktrees created in subdirectories (e.g., .worktrees/foo)
// where the name shown in "bd worktree list" doesn't match a simple path
// #nosec G204 - repoRoot comes from git.GetRepoRoot()
gitCmd := exec.Command("git", "worktree", "list", "--porcelain")
gitCmd.Dir = repoRoot
output, err := gitCmd.CombinedOutput()
if err == nil {
worktrees := parseWorktreeList(string(output))
for _, wt := range worktrees {
if wt.Name == name || wt.Path == name {
if _, err := os.Stat(wt.Path); err == nil {
return wt.Path, nil
}
}
}
}
return "", fmt.Errorf("worktree not found: %s", name)
}