Skip to content

Comments

fix: run git from mainRoot only if we deleted the current worktree#137

Merged
k1LoW merged 1 commit intok1LoW:mainfrom
yoichi:invoke-branch-d-in-current-worktree
Feb 14, 2026
Merged

fix: run git from mainRoot only if we deleted the current worktree#137
k1LoW merged 1 commit intok1LoW:mainfrom
yoichi:invoke-branch-d-in-current-worktree

Conversation

@yoichi
Copy link
Contributor

@yoichi yoichi commented Feb 14, 2026

Summary of the change

Run git from mainRoot only if we deleted the current worktree

If no upstream for the branch was set, git checks the target branch is fully merged in HEAD. Because HEAD depends on the current working directory and git-wt >= v0.11.0 always specifies "-C mainRoot" to git command, the branch deletion behavior of git-wt was different from the behavior of git branch -d.

This change allows git-wt to specify "-C mainRoot" only if the current working tree is the one being deleted.
It also ensures consistent behavior with deleting branches that have no worktree.

Problem to be solved

Try renaming the local branch and worktree by copying them and deleting the originals:

yoichi@Mac repo % git --version
git version 2.53.0
yoichi@Mac repo % git wt --version
git version 0.20.0
yoichi@Mac repo % git wt a
Preparing worktree (new branch 'a')
HEAD is now at e5583de init
yoichi@Mac a % git commit --allow-empty -m "a"
[a 91aba8a] a
yoichi@Mac a % git wt b
Preparing worktree (new branch 'b')
HEAD is now at 91aba8a a
yoichi@Mac b % git wt -d a
error: the branch 'a' is not fully merged
hint: If you are sure you want to delete it, run 'git branch -D a'
hint: Disable this message with "git config set advice.forceDeleteBranch false"
Deleted worktree, but failed to delete branch "a" (use -D to force)

Since the target branch 'a' is at the same revision as the current branch 'b',
deleting the branch 'a' is expected to succeed.

Furthermore, this behavior is inconsistent with git-wt's behavior of deleting branches that are not associated with any worktree.
We can verify the latter by running the command again:

yoichi@Mac b % git wt -d a
Deleted branch a (was 91aba8a).
Deleted branch "a" (no worktree was associated)

If no upstream for the branch was set, git checks the target branch is
fully merged in HEAD. Because HEAD depends on the current working
directory and git-wt >= v0.11.0 always specifies "-C mainRoot" to git
command, the branch deletion behavior of git-wt was different from the
behavior of git branch -d.

This change allows git-wt to specify "-C mainRoot" only if the current
working tree is the one being deleted.
It also ensures consistent behavior with deleting branches that have
no worktree.
@k1LoW k1LoW added the bug Something isn't working label Feb 14, 2026
Copy link
Owner

@k1LoW k1LoW left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM!

@k1LoW k1LoW merged commit db9ae1e into k1LoW:main Feb 14, 2026
3 checks passed
@github-actions github-actions bot mentioned this pull request Feb 14, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants