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

Re: Bug: git worktree remove and overwritten directory

From
Jonathan Müller <jonathanmueller.dev@gmail.com>
Date
May 20, 2020, 14:28 UTC
Message-ID
<dd7c3a11-6537-74ec-053c-0c9c946c5f19@gmail.com>
In-Reply-To
<CAPig+cTU8+N6Chimpoa2_T-TcXxw-3B9-9pjCLz7WeOh472P_A@mail.gmail.com>
On 20.05.20 16:22, Eric Sunshine wrote:
Show 6 quoted lines
> Git tries hard to prevent the same directory from being registered to
> multiple worktrees, however, there is not much it can do to prevent a
> person from shooting himself in the foot by making changes like this
> outside of Git's control. Thus, this seems like a case of "if it
> hurts, don't do it".
> 
I agree and didn't expect git to "work".
Show 5 quoted lines
> However, "git worktree" could possibly do a better job of helping you
> recover from such a situation. In particular, I think it should be
> reasonably easy to enhance "git worktree prune" to detect this
> situation and automatically prune the non-main now-bogus worktree
> entry.

At the very least, the somewhat confusing error message could be replaced by a "you messed up the worktrees, please delete the corresponding entry in .git/worktree" or something like that. But enhancing `git worktree prune` would be better. It was, in fact, the first command I ran to try and fix the problem.

Show 6 quoted lines
> It may be possible to special-case "git worktree remove" to detect
> this situation and automatically prune the bogus entry too, but I'm
> quite hesitant to suggest that sort of special case both because the
> implementation would likely be ugly, and it could lead to a plethora
> of additional ugly special-cases as people discover even more ways to
> shoot themselves in the feet.

As said above, I think git worktree remove could issue a better error if it detects multiple worktrees with an identical path.

Previous: Eric SunshineNext: Eric Sunshine
Message 4 of 6 in “Bug: git worktree remove and overwritten directory”
  1. Jonathan MüllerMay 20, 2020
  2. Shourya ShuklaMay 20, 2020
  3. Eric SunshineMay 20, 2020
  4. Jonathan MüllerMay 20, 2020
  5. Eric SunshineJun 8, 2020
  6. Jonathan MüllerJun 8, 2020

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.