Skip to content

Commit 5154c47

Browse files
nsheapsclaude
andcommitted
feat: show root checkout in worktree list
- Display root checkout as ๐Ÿ  [root] at top of existing checkouts - Track root checkout's branch in WORKTREE_BRANCHES to exclude it from selectable branches (prevents duplicate worktree creation) - Rename [existing] to [worktree] for clearer distinction - Add selection handler for root checkout option Co-Authored-By: Claude Code (User Settings, in: ${CLAUDE_PROJECT_DIR}) <noreply@anthropic.com>
1 parent e8c1c34 commit 5154c47

1 file changed

Lines changed: 28 additions & 12 deletions

File tree

โ€Žbin/git-wtโ€Ž

Lines changed: 28 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -306,18 +306,21 @@ echo ""
306306
gum style --bold "Git Worktree Selector"
307307
echo ""
308308

309-
# Get existing worktrees (excluding main) and track their branches
309+
# Get existing worktrees (including root checkout) and track their branches
310310
WORKTREES=()
311+
ROOT_CHECKOUT=""
311312
declare -A WORKTREE_BRANCHES
312313
while IFS= read -r line; do
313-
# Skip the main worktree
314-
if [[ "$line" != "$GIT_ROOT" ]]; then
314+
# Track root checkout separately so it appears first
315+
if [[ "$line" == "$GIT_ROOT" ]]; then
316+
ROOT_CHECKOUT="$line"
317+
else
315318
WORKTREES+=("$line")
316-
# Track which branch this worktree is on for deduplication
317-
local_branch=$(git -C "$line" branch --show-current 2>/dev/null || echo "")
318-
if [[ -n "$local_branch" ]]; then
319-
WORKTREE_BRANCHES["$local_branch"]=1
320-
fi
319+
fi
320+
# Track which branch this worktree is on for deduplication
321+
local_branch=$(git -C "$line" branch --show-current 2>/dev/null || echo "")
322+
if [[ -n "$local_branch" ]]; then
323+
WORKTREE_BRANCHES["$local_branch"]=1
321324
fi
322325
done < <(git -C "$GIT_ROOT" worktree list --porcelain | grep "^worktree " | cut -d' ' -f2-)
323326

@@ -335,10 +338,16 @@ done < <(git -C "$GIT_ROOT" branch --format='%(refname:short)' 2>/dev/null || ec
335338
MENU_OPTIONS=()
336339
MENU_OPTIONS+=("๐Ÿ“ (create new worktree)")
337340

338-
# Add existing worktrees first
341+
# Add root checkout first (if found)
342+
if [[ -n "$ROOT_CHECKOUT" ]]; then
343+
root_branch=$(git -C "$ROOT_CHECKOUT" branch --show-current 2>/dev/null || echo "detached")
344+
MENU_OPTIONS+=("๐Ÿ  [root] $root_branch โ†’ $ROOT_CHECKOUT")
345+
fi
346+
347+
# Add existing worktrees
339348
for wt in "${WORKTREES[@]}"; do
340349
wt_branch=$(git -C "$wt" branch --show-current 2>/dev/null || echo "detached")
341-
MENU_OPTIONS+=("๐Ÿ“‚ [existing] $wt_branch โ†’ $wt")
350+
MENU_OPTIONS+=("๐Ÿ“‚ [worktree] $wt_branch โ†’ $wt")
342351
done
343352

344353
# Add branches (sorted)
@@ -394,11 +403,18 @@ case "$SELECTED" in
394403
echo "Branch: $BRANCH_NAME (based on $BASE_BRANCH)"
395404
;;
396405

397-
"๐Ÿ“‚ [existing]"*)
406+
"๐Ÿ  [root]"*)
407+
# Extract path from selection
408+
FINAL_PATH=$(echo "$SELECTED" | sed 's/.*โ†’ //')
409+
echo ""
410+
echo "Selected root checkout: $FINAL_PATH"
411+
;;
412+
413+
"๐Ÿ“‚ [worktree]"*)
398414
# Extract path from selection
399415
FINAL_PATH=$(echo "$SELECTED" | sed 's/.*โ†’ //')
400416
echo ""
401-
echo "Selected existing worktree: $FINAL_PATH"
417+
echo "Selected worktree: $FINAL_PATH"
402418
;;
403419

404420
"๐Ÿ”„ (switch repository)")

0 commit comments

Comments
ย (0)
โšก