threads / discuss / 44815

git branch -D doesn't work with deleted worktree

Subject: git branch -D doesn't work with deleted worktree

## tl;dr

7 messages between Jan 5, 2017 and Jan 10, 2017.

replies: 6people: 4as markdown or json

Roland Illig· Jan 5, 2017, 10:06 UTC · lore
Git 2.11.0 gives a wrong error message after the following commands:
 
$ git init
$ echo hello >file
$ git add file
$ git commit -m "message"
$ git worktree add ../worktree
$ rm -rf ../worktree
$ git br -D worktree
error: Cannot delete branch 'worktree' checked out at '../worktree'
Since ../worktree has been deleted, there cannot be anything checked out at that location.
In my opinion, deleting the branch should just work. Especially since I used the -D option and the "git worktree" documentation says "When you are done with a linked working tree you can simply delete it."

Regards, Roland

Stefan Beller· Jan 5, 2017, 14:02 UTC · re: Roland Illig · lore

Re: git branch -D doesn't work with deleted worktree

On Thu, Jan 5, 2017 at 2:06 AM, Roland Illig <rillig@novomind.com> wrote:
Show 18 quoted lines
> Git 2.11.0 gives a wrong error message after the following commands:
>
> $ git init
> $ echo hello >file
> $ git add file
> $ git commit -m "message"
> $ git worktree add ../worktree
> $ rm -rf ../worktree
> $ git br -D worktree
> error: Cannot delete branch 'worktree' checked out at '../worktree'
>
> Since ../worktree has been deleted, there cannot be anything checked out at that location.
>
> In my opinion, deleting the branch should just work. Especially since I used the -D option and the "git worktree" documentation says "When you are done with a linked working tree you can simply delete it."
>
> Regards,
> Roland
>
Duy Nguyen· Jan 6, 2017, 10:05 UTC · re: Stefan Beller · lore

Re: git branch -D doesn't work with deleted worktree

On Thu, Jan 5, 2017 at 9:02 PM, Stefan Beller <sbeller@google.com> wrote:
Show 15 quoted lines
> On Thu, Jan 5, 2017 at 2:06 AM, Roland Illig <rillig@novomind.com> wrote:
>> Git 2.11.0 gives a wrong error message after the following commands:
>>
>> $ git init
>> $ echo hello >file
>> $ git add file
>> $ git commit -m "message"
>> $ git worktree add ../worktree
>> $ rm -rf ../worktree
>> $ git br -D worktree
>> error: Cannot delete branch 'worktree' checked out at '../worktree'
>>
>> Since ../worktree has been deleted, there cannot be anything checked out at that location.
>>
>> In my opinion, deleting the branch should just work. Especially since I used the -D option and the "git worktree" documentation says "When you are done with a linked working tree you can simply delete it."

Since -D means "I know what I'm doing, get out of my way", maybe we should continue if any worktree has the branch checked out by detaching it?

(Yes I'm carefully tip toeing around the deleted worktree issue since "git worktree remove" is coming. After that point, running "worktree prune" before "branch -D" does not sound so bad)

-- 
Duy
Jacob Keller· Jan 9, 2017, 03:44 UTC · re: Duy Nguyen · lore

Re: git branch -D doesn't work with deleted worktree

On Fri, Jan 6, 2017 at 2:05 AM, Duy Nguyen <pclouds@gmail.com> wrote:
Show 26 quoted lines
> On Thu, Jan 5, 2017 at 9:02 PM, Stefan Beller <sbeller@google.com> wrote:
>> On Thu, Jan 5, 2017 at 2:06 AM, Roland Illig <rillig@novomind.com> wrote:
>>> Git 2.11.0 gives a wrong error message after the following commands:
>>>
>>> $ git init
>>> $ echo hello >file
>>> $ git add file
>>> $ git commit -m "message"
>>> $ git worktree add ../worktree
>>> $ rm -rf ../worktree
>>> $ git br -D worktree
>>> error: Cannot delete branch 'worktree' checked out at '../worktree'
>>>
>>> Since ../worktree has been deleted, there cannot be anything checked out at that location.
>>>
>>> In my opinion, deleting the branch should just work. Especially since I used the -D option and the "git worktree" documentation says "When you are done with a linked working tree you can simply delete it."
>
> Since -D means "I know what I'm doing, get out of my way", maybe we
> should continue if any worktree has the branch checked out by
> detaching it?
>
> (Yes I'm carefully tip toeing around the deleted worktree issue since
> "git worktree remove" is coming. After that point, running "worktree
> prune" before "branch -D" does not sound so bad)
> --
> Duy

Why not just update the documentation to be "when you are done with a work tree you can delete it and then run git worktree prune"?

Thanks, Jake

Duy Nguyen· Jan 9, 2017, 10:07 UTC · re: Jacob Keller · lore

Re: git branch -D doesn't work with deleted worktree

On Mon, Jan 9, 2017 at 10:44 AM, Jacob Keller <jacob.keller@gmail.com> wrote:
> Why not just update the documentation to be "when you are done with a
> work tree you can delete it and then run git worktree prune"?
The document does say that (a bit verbose though):

When you are done with a linked working tree you can simply delete it. The working tree's administrative files in the repository (see "DETAILS" below) will eventually be removed automatically (see `gc.worktreePruneExpire` in linkgit:git-config[1]), or you can run `git worktree prune` in the main or any linked working tree to clean up any stale administrative files.

-- 
Duy
Jacob Keller· Jan 10, 2017, 05:08 UTC · re: Duy Nguyen · lore

Re: git branch -D doesn't work with deleted worktree

On Mon, Jan 9, 2017 at 2:07 AM, Duy Nguyen <pclouds@gmail.com> wrote:
Show 14 quoted lines
> On Mon, Jan 9, 2017 at 10:44 AM, Jacob Keller <jacob.keller@gmail.com> wrote:
>> Why not just update the documentation to be "when you are done with a
>> work tree you can delete it and then run git worktree prune"?
>
> The document does say that (a bit verbose though):
>
> When you are done with a linked working tree you can simply delete it.
> The working tree's administrative files in the repository (see
> "DETAILS" below) will eventually be removed automatically (see
> `gc.worktreePruneExpire` in linkgit:git-config[1]), or you can run
> `git worktree prune` in the main or any linked working tree to
> clean up any stale administrative files.
> --
> Duy

Right, so maybe we can make it more clear since it's not quite as simple as "deleting the work tree" because of stuff like stale branches.. or would it be worth re-scanning worktrees when we do branch deletion? (obviously ignoring the ones that are marked as on removable media)

Thanks, Jake

Duy Nguyen· Jan 10, 2017, 10:47 UTC · re: Jacob Keller · lore

Re: git branch -D doesn't work with deleted worktree

On Tue, Jan 10, 2017 at 12:08 PM, Jacob Keller <jacob.keller@gmail.com> wrote:
Show 19 quoted lines
> On Mon, Jan 9, 2017 at 2:07 AM, Duy Nguyen <pclouds@gmail.com> wrote:
>> On Mon, Jan 9, 2017 at 10:44 AM, Jacob Keller <jacob.keller@gmail.com> wrote:
>>> Why not just update the documentation to be "when you are done with a
>>> work tree you can delete it and then run git worktree prune"?
>>
>> The document does say that (a bit verbose though):
>>
>> When you are done with a linked working tree you can simply delete it.
>> The working tree's administrative files in the repository (see
>> "DETAILS" below) will eventually be removed automatically (see
>> `gc.worktreePruneExpire` in linkgit:git-config[1]), or you can run
>> `git worktree prune` in the main or any linked working tree to
>> clean up any stale administrative files.
>> --
>> Duy
>
> Right, so maybe we can make it more clear since it's not quite as
> simple as "deleting the work tree" because of stuff like stale
> branches..

Patches are welcome. I wrote that paragraph and you could clearly see its "quality" (from user perspective).

> or would it be worth re-scanning worktrees when we do
> branch deletion? (obviously ignoring the ones that are marked as on
> removable media)

Probably. We run "git worktree prune" as part of "git gc" and that command is automatically called in a couple places. Adding another "git gc" here probably does not hurt. However it could trigger a full repack and make "git branch" hang for a few seconds...

And no I don't want to single out "git worktree prune" to be called in git-branch. We should either go through git-gc or none. We could check if a worktree is deleted and suggest the user to run "git gc" though, but it's getting too complicated when "git worktree remove" will soon be the recommended way of deleting a worktree. So.. I don't know..

-- 
Duy

← back to recent threads