Re: git branch doesn't allow me to forcibly delete branch which was checked out in a now-deleted worktree dir
- From
Jacob Keller <jacob.keller@gmail.com>
- Date
- Jul 9, 2016, 00:41 UTC
- Message-ID
- <CA+P7+xr_dYbno+JsTmaG+WWrgwsAXXGTyA6HL4A4A34ahHMD=Q@mail.gmail.com>
- In-Reply-To
- <20160708003646.GB1916@gmail.com>
On Thu, Jul 7, 2016 at 5:36 PM, Erik Johnson <palehose@gmail.com> wrote:
Show 5 quoted lines
> I'm not expecting _any_ git branch command to prune worktrees, but a > branch _deletion_ shouldn't fail because git thinks the branch is > checked out in a worktree that doesn't exist anymore. Even in the > scenario where the worktree corresponding to that branch is on removable > media, does it really matter? You're trying to delete the branch.
I disagree. git branch -d (should) fail to delete a branch when it is checked out in a worktree. If the worktree is a persistent (ie: not there due to removable media etc) directory then it *definitely* shouldn't allow you to delete.
It is possible we should update "git branch -d" should perform a worktree prune first, since that would enable it to determine that you deleted the directory, and any worktree which is removable should be marked as persistent.
Given that there is a known workaround (git worktree prune) and that it is expected behavior for a branch checked out to prevent deletion, I think the best coarse of action would be to patch git branch -d to do a prune before attempting to delete.
Thanks, Jake