fix(git-worktree): detect worktrees where .git is a file, not a directory (#159)

In git worktrees, .git is a regular file containing a gitdir: pointer
back to the main repository — not a directory. The -d check caused
list and cleanup to silently skip all worktrees, reporting "No
worktrees found". Changed to -e (exists) which handles both cases.

Fixes #158

Co-authored-by: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
David Alley
2026-02-08 16:41:44 -06:00
committed by GitHub
parent e4ff6a874c
commit 0c404f9544

View File

@@ -134,7 +134,7 @@ list_worktrees() {
local count=0
for worktree_path in "$WORKTREE_DIR"/*; do
if [[ -d "$worktree_path" && -d "$worktree_path/.git" ]]; then
if [[ -d "$worktree_path" && -e "$worktree_path/.git" ]]; then
count=$((count + 1))
local worktree_name=$(basename "$worktree_path")
local branch=$(git -C "$worktree_path" rev-parse --abbrev-ref HEAD 2>/dev/null || echo "unknown")
@@ -231,7 +231,7 @@ cleanup_worktrees() {
local to_remove=()
for worktree_path in "$WORKTREE_DIR"/*; do
if [[ -d "$worktree_path" && -d "$worktree_path/.git" ]]; then
if [[ -d "$worktree_path" && -e "$worktree_path/.git" ]]; then
local worktree_name=$(basename "$worktree_path")
# Skip if current worktree