All of lore.kernel.org
 help / color / mirror / Atom feed
* bug report: spurious "cannot delete branch '%s' used by worktree"
@ 2024-03-28 14:53 Tamir Duberstein
  2024-03-28 17:24 ` Eric Sunshine
  0 siblings, 1 reply; 11+ messages in thread
From: Tamir Duberstein @ 2024-03-28 14:53 UTC (permalink / raw)
  To: git

Pasting the output of `git bugreport`:

Thank you for filling out a Git bug report!
Please answer the following questions to help us understand your issue.

What did you do before the bug happened? (Steps to reproduce your issue)

I created a branch, pushed to a remote, and then the remote deleted the branch.
Then I tried to delete the local branch.

What did you expect to happen? (Expected behavior)

The branch to be deleted.

What happened instead? (Actual behavior)

% 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

What's different between what you expected and what actually happened?

Git reports the branch is being used by a worktree, but prints the current
repository's directory, where a different branch is clearly checked out.

Anything else you want to add:

Please review the rest of the bug report below.
You can delete any lines you don't wish to share.


[System Info]
git version:
git version 2.44.0
cpu: arm64
no commit associated with this build
sizeof-long: 8
sizeof-size_t: 8
shell-path: /bin/sh
feature: fsmonitor--daemon
uname: Darwin 23.4.0 Darwin Kernel Version 23.4.0: Fri Mar 15 00:12:25
PDT 2024; root:xnu-10063.101.17~1/RELEASE_ARM64_T6030 arm64
compiler info: clang: 15.0.0 (clang-1500.1.0.2.5)
libc info: no libc information available
$SHELL (typically, interactive shell): /bin/zsh


[Enabled Hooks]

^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: bug report: spurious "cannot delete branch '%s' used by worktree"
  2024-03-28 14:53 bug report: spurious "cannot delete branch '%s' used by worktree" Tamir Duberstein
@ 2024-03-28 17:24 ` Eric Sunshine
  2024-03-28 17:39   ` Tamir Duberstein
  0 siblings, 1 reply; 11+ messages in thread
From: Eric Sunshine @ 2024-03-28 17:24 UTC (permalink / raw)
  To: Tamir Duberstein; +Cc: git

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?

^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: bug report: spurious "cannot delete branch '%s' used by worktree"
  2024-03-28 17:24 ` Eric Sunshine
@ 2024-03-28 17:39   ` Tamir Duberstein
  2024-03-31  6:49     ` Eric Sunshine
  0 siblings, 1 reply; 11+ messages in thread
From: Tamir Duberstein @ 2024-03-28 17:39 UTC (permalink / raw)
  To: Eric Sunshine; +Cc: git

Yes, the problem is persistent. The branch is never deleted.


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?

^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: bug report: spurious "cannot delete branch '%s' used by worktree"
  2024-03-28 17:39   ` Tamir Duberstein
@ 2024-03-31  6:49     ` Eric Sunshine
  2024-03-31  7:45       ` Tamir Duberstein
  2024-04-02 10:10       ` Phillip Wood
  0 siblings, 2 replies; 11+ messages in thread
From: Eric Sunshine @ 2024-03-31  6:49 UTC (permalink / raw)
  To: Tamir Duberstein; +Cc: git, Phillip Wood

[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.]

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

^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: bug report: spurious "cannot delete branch '%s' used by worktree"
  2024-03-31  6:49     ` Eric Sunshine
@ 2024-03-31  7:45       ` Tamir Duberstein
  2024-04-02 10:10       ` Phillip Wood
  1 sibling, 0 replies; 11+ messages in thread
From: Tamir Duberstein @ 2024-03-31  7:45 UTC (permalink / raw)
  To: Eric Sunshine; +Cc: git, Phillip Wood

On Sun, Mar 31, 2024 at 7:49 AM Eric Sunshine <sunshine@sunshineco.com> 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.]
>
> 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

Thanks, I wasn't aware of the etiquette.

I had used the branch to send a pull request on GitHub, and then
deleted the remote branch from GitHub after merging the pull request.
Yes, I have fetched from the remote following that. I've also manually
removed the remote tracking branch. Symptoms remain unchanged.

If you can suggest where to go looking for stale state, I'm happy to
provide more information. I'll take a look at the code references as
well.

^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: bug report: spurious "cannot delete branch '%s' used by worktree"
  2024-03-31  6:49     ` Eric Sunshine
  2024-03-31  7:45       ` Tamir Duberstein
@ 2024-04-02 10:10       ` Phillip Wood
  2024-04-02 10:26         ` Tamir Duberstein
  1 sibling, 1 reply; 11+ messages in thread
From: Phillip Wood @ 2024-04-02 10:10 UTC (permalink / raw)
  To: Eric Sunshine, Tamir Duberstein; +Cc: git

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?

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

^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: bug report: spurious "cannot delete branch '%s' used by worktree"
  2024-04-02 10:10       ` Phillip Wood
@ 2024-04-02 10:26         ` Tamir Duberstein
  2024-04-02 10:38           ` Kristoffer Haugsbakk
  2024-04-02 11:28           ` phillip.wood123
  0 siblings, 2 replies; 11+ messages in thread
From: Tamir Duberstein @ 2024-04-02 10:26 UTC (permalink / raw)
  To: phillip.wood; +Cc: Eric Sunshine, git

Hi Phillip

On Tue, Apr 2, 2024 at 11:10 AM Phillip Wood <phillip.wood123@gmail.com> wrote:
>
> 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.

> 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

^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: bug report: spurious "cannot delete branch '%s' used by worktree"
  2024-04-02 10:26         ` Tamir Duberstein
@ 2024-04-02 10:38           ` Kristoffer Haugsbakk
  2024-04-02 11:28           ` phillip.wood123
  1 sibling, 0 replies; 11+ messages in thread
From: Kristoffer Haugsbakk @ 2024-04-02 10:38 UTC (permalink / raw)
  To: Tamir Duberstein; +Cc: Eric Sunshine, git, Phillip Wood

On Tue, Apr 2, 2024, at 12:26, Tamir Duberstein wrote:
>
> % 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.

Have you tried `git worktree repair`?

-- 
Kristoffer Haugsbakk


^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: bug report: spurious "cannot delete branch '%s' used by worktree"
  2024-04-02 10:26         ` Tamir Duberstein
  2024-04-02 10:38           ` Kristoffer Haugsbakk
@ 2024-04-02 11:28           ` phillip.wood123
  2024-04-02 11:56             ` Tamir Duberstein
  1 sibling, 1 reply; 11+ messages in thread
From: phillip.wood123 @ 2024-04-02 11:28 UTC (permalink / raw)
  To: Tamir Duberstein, phillip.wood; +Cc: Eric Sunshine, git

Hi Tamir

On 02/04/2024 11:26, Tamir Duberstein wrote:
> On Tue, Apr 2, 2024 at 11:10 AM Phillip Wood <phillip.wood123@gmail.com> wrote:
>> On 31/03/2024 07:49, Eric Sunshine wrote:
>> 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

Thanks for trying that - at least we know it isn't a problem with 
rebase. Lets check if there is a stale bisect (sorry I forgot about that 
earlier). What do

     cat .git/BISECT_START
     ls .git | grep -i bisect

show?

> Yes, it's the only worktree.
In that case can you check that

     ls .git/worktrees

fails because the directory is missing or shows an empty directory please.

Thanks

Phillip

^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: bug report: spurious "cannot delete branch '%s' used by worktree"
  2024-04-02 11:28           ` phillip.wood123
@ 2024-04-02 11:56             ` Tamir Duberstein
  2024-04-02 15:15               ` phillip.wood123
  0 siblings, 1 reply; 11+ messages in thread
From: Tamir Duberstein @ 2024-04-02 11:56 UTC (permalink / raw)
  To: phillip.wood; +Cc: Eric Sunshine, git

On Tue, Apr 2, 2024 at 12:29 PM <phillip.wood123@gmail.com> wrote:
>
> Hi Tamir
>
> On 02/04/2024 11:26, Tamir Duberstein wrote:
> > On Tue, Apr 2, 2024 at 11:10 AM Phillip Wood <phillip.wood123@gmail.com> wrote:
> >> On 31/03/2024 07:49, Eric Sunshine wrote:
> >> 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
>
> Thanks for trying that - at least we know it isn't a problem with
> rebase. Lets check if there is a stale bisect (sorry I forgot about that
> earlier). What do
>
>      cat .git/BISECT_START
>      ls .git | grep -i bisect
>
> show?

This was the culprit! There was indeed a ` .git/BISECT_START`
containing "cleanup". After deleting this file I am able to remove the
branch.

> > Yes, it's the only worktree.
> In that case can you check that
>
>      ls .git/worktrees
>
> fails because the directory is missing or shows an empty directory please.

% cat .git/worktrees

cat: .git/worktrees: No such file or directory

> Thanks
>
> Phillip

I guess the only action item would be to improve the error message.

^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: bug report: spurious "cannot delete branch '%s' used by worktree"
  2024-04-02 11:56             ` Tamir Duberstein
@ 2024-04-02 15:15               ` phillip.wood123
  0 siblings, 0 replies; 11+ messages in thread
From: phillip.wood123 @ 2024-04-02 15:15 UTC (permalink / raw)
  To: Tamir Duberstein, phillip.wood; +Cc: Eric Sunshine, git, Christian Couder

On 02/04/2024 12:56, Tamir Duberstein wrote:

[cc'ing Christian who knows more about "git bisect" than me]

> On Tue, Apr 2, 2024 at 12:29 PM <phillip.wood123@gmail.com> wrote:
>> On 02/04/2024 11:26, Tamir Duberstein wrote:
>>> On Tue, Apr 2, 2024 at 11:10 AM Phillip Wood <phillip.wood123@gmail.com> wrote:
>>>> On 31/03/2024 07:49, Eric Sunshine wrote:
>> Thanks for trying that - at least we know it isn't a problem with
>> rebase. Lets check if there is a stale bisect (sorry I forgot about that
>> earlier). What do
>>
>>       cat .git/BISECT_START
>>       ls .git | grep -i bisect
>>
>> show?
> 
> This was the culprit! There was indeed a ` .git/BISECT_START`
> containing "cleanup". After deleting this file I am able to remove the
> branch.

Oh good I'm glad we've found the problem.

> I guess the only action item would be to improve the error message.

Yes, there was some discussion about that relatively recently when the 
message was changed to say "in use" rather than "checked out". Adding 
the appropriate command name into the message would help.

When bisecting "git switch" prints a warning but still switches 
branches, "git checkout" performs the checkout with no warning. I wonder 
if (a) "git switch" should refuse to run without "--detach" when there 
is a bisection in progress and (b) if "git bisect" could be more helpful 
when it finds the broken commit by telling the user that they should run 
"git bisect reset" to clean up.

Best Wishes

Phillip

^ permalink raw reply	[flat|nested] 11+ messages in thread

end of thread, other threads:[~2024-04-02 15:15 UTC | newest]

Thread overview: 11+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2024-03-28 14:53 bug report: spurious "cannot delete branch '%s' used by worktree" Tamir Duberstein
2024-03-28 17:24 ` Eric Sunshine
2024-03-28 17:39   ` Tamir Duberstein
2024-03-31  6:49     ` Eric Sunshine
2024-03-31  7:45       ` Tamir Duberstein
2024-04-02 10:10       ` Phillip Wood
2024-04-02 10:26         ` Tamir Duberstein
2024-04-02 10:38           ` Kristoffer Haugsbakk
2024-04-02 11:28           ` phillip.wood123
2024-04-02 11:56             ` Tamir Duberstein
2024-04-02 15:15               ` phillip.wood123

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.