git/list[1] front-page[2] threads[3] people[4] search[5] about
 

Re: bug report: spurious "cannot delete branch '%s' used by worktree"

From
TDTamir Duberstein <tamird@fuseenergy.com>
Date
Apr 2, 2024, 10:26 UTC
Message-ID
<CAEYvasmb1TjwWpSbfSAogbOiB64sZQiHVoUhxvY+NoLmXnRuHA@mail.gmail.com>
In-Reply-To
<4041487e-d8d8-481c-b490-884e31f533a8@gmail.com>
Hi Phillip
On Tue, Apr 2, 2024 at 11:10 AM Phillip Wood <phillip.wood123@gmail.com> wrote:
Show 42 quoted lines
>
> Hi Tamir
>
> On 31/03/2024 07:49, Eric Sunshine wrote:
> > [please reply inline rather than top-posting; I've moved your reply
> > inline for this response]
> >
> > On Thu, Mar 28, 2024 at 1:40 PM Tamir Duberstein <tamird@fuseenergy.com> wrote:
> >> On Thu, Mar 28, 2024 at 5:24 PM Eric Sunshine <sunshine@sunshineco.com> wrote:
> >>> On Thu, Mar 28, 2024 at 10:54 AM Tamir Duberstein <tamird@fuseenergy.com> wrote:
> >>>> % git branch -d cleanup
> >>>> error: cannot delete branch 'cleanup' used by worktree at '<my source dir>'
> >>>> % git worktree list
> >>>> <my source dir>  dc46f6d5e [main]
> >>>> % git branch
> >>>>    cleanup
> >>>> * main
> >>>
> >>> Is this error persistent once it arises? That is, if you invoke `git
> >>> branch -d cleanup` again immediately after (or a little while after)
> >>> the above sequence, does the problem persist? Or does it "clear up" on
> >>> its own at some point?
> >>
> >> Yes, the problem is persistent. The branch is never deleted.
> >
> > I'd guess that there may be some sort of "ref" still pointing at the
> > "cleanup" branch which presumably was, at some point, checked out at
> > "<my source dir>". Digging through the code[1,2,3] suggests that you
> > might have some stale state from a rebase, bisect, or other sequencer
> > operation which still references the "cleanup" branch.
> >
> > [Cc'ing Phillip who is probably much more familiar with this code than am I.]
>
> Thanks Eric. I'd have thought that "git worktree list" would say
> something about the branch being rebased if there was enough state lying
> around to prevent the branch being deleted, but lets see. What does
>
>      ls $(git rev-parse --git-path rebase-merge) $(git rev-parse
> --git-path rebase-apply)
>
> show when you run it in <my source dir>? Also is <my source dir> the
> only worktree?

% ls $(git rev-parse --git-path rebase-merge) $(git rev-parse --git-path rebase-apply) ls: .git/rebase-apply: No such file or directory ls: .git/rebase-merge: No such file or directory

Yes, it's the only worktree.
Show 11 quoted lines
> Best Wishes
>
> Phillip
>
> > By the way, it's not clear from your initial report what you mean when
> > you say "then the remote deleted the branch". Also, did you fetch
> > and/or pull from the remote after that?
> >
> > [1]: https://github.com/git/git/blob/d6fd04375f91/branch.c#L454
> > [2]: https://github.com/git/git/blob/d6fd04375f91/branch.c#L386
> > [3]: https://github.com/git/git/blob/d6fd04375f91/sequencer.c#L6551
Previous: Phillip WoodNext: Kristoffer Haugsbakk
Message 7 of 11 in “bug report: spurious "cannot delete branch '%s' used by worktree"”
  1. Tamir DubersteinMar 28, 2024
  2. Eric SunshineMar 28, 2024
  3. Tamir DubersteinMar 28, 2024
  4. Eric SunshineMar 31, 2024
  5. Tamir DubersteinMar 31, 2024
  6. Phillip WoodApr 2, 2024
  7. Tamir DubersteinApr 2, 2024
  8. Kristoffer HaugsbakkApr 2, 2024
  9. phillip.wood123@gmail.comApr 2, 2024
  10. Tamir DubersteinApr 2, 2024
  11. phillip.wood123@gmail.comApr 2, 2024

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.