Skip to content

fix: cd to safe directory when branch-delete removes current worktree#234

Merged
avihut merged 1 commit intomasterfrom
fix/worktree-branch-delete-doesnt-cd
Feb 18, 2026
Merged

fix: cd to safe directory when branch-delete removes current worktree#234
avihut merged 1 commit intomasterfrom
fix/worktree-branch-delete-doesnt-cd

Conversation

@avihut
Copy link
Owner

@avihut avihut commented Feb 18, 2026

Summary

  • Shell wrapper (bash/zsh/fish) now always checks DAFT_CD_FILE regardless of exit code — previously it only checked on success, so partial errors (e.g., remote branch deletion failure) would leave the user stranded in a deleted directory
  • Made current-worktree detection in branch_delete more robust with path canonicalization and branch name fallback (matching the pattern used in prune)
  • Added integration tests for deleting from inside the current worktree with both cdTarget=root and cdTarget=default-branch

Test plan

  • mise run fmt-check — passes
  • mise run clippy — passes
  • mise run test-unit — 333 passed
  • Integration tests: all 10 branch_delete tests pass (both default and gitoxide matrices)
  • All 19 prune tests still pass (shell wrapper change is backwards compatible)
  • Manual test: git worktree-branch-delete from inside worktree correctly cd's to safe directory

🤖 Generated with Claude Code

Two bugs prevented worktree-branch-delete from changing directory to a
safe location when deleting the worktree the user is currently inside:

1. Shell wrapper (bash/zsh/fish) only checked DAFT_CD_FILE when exit
   code was 0. But branch-delete can exit non-zero due to partial errors
   (e.g., remote branch deletion failure) even after successfully removing
   the worktree. The user's CWD is gone but the wrapper skipped the cd.

2. Current-worktree detection relied solely on exact path string
   comparison between git rev-parse and git worktree list output. Added
   path canonicalization and branch name fallback for robustness.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@avihut avihut added this to the v1.1.0 milestone Feb 18, 2026
@avihut avihut added bug Something isn't working fix Bug fix labels Feb 18, 2026
@avihut avihut self-assigned this Feb 18, 2026
@avihut avihut merged commit c94d6dd into master Feb 18, 2026
6 checks passed
@avihut avihut deleted the fix/worktree-branch-delete-doesnt-cd branch February 18, 2026 19:57
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working fix Bug fix

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant