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

Re: [PATCH 3/5] worktree: teach "repair" to fix outgoing links to worktrees

From
Eric Sunshine <sunshine@sunshineco.com>
Date
Aug 30, 2020, 07:36 UTC
Message-ID
<CAPig+cT-w6LV490MGNyG_ihWkSzdgfnEBrjQCsafjndTRmMgFA@mail.gmail.com>
In-Reply-To
<xmqqh7soqady.fsf@gitster.c.googlers.com>
On Thu, Aug 27, 2020 at 1:14 PM Junio C Hamano <gitster@pobox.com> wrote:
Show 11 quoted lines
> Eric Sunshine <sunshine@sunshineco.com> writes:
> > Therefore, teach "git worktree repair" how to repair broken or outdated
> > .git/worktrees/<id>/gitdir files automatically. (For this to work, the
> > command must either be invoked from within the worktree whose gitdir
> > file requires repair, or from within the main or any linked worktree by
> > providing the path of the broken worktree as an argument to "git
> > worktree repair".)
>
> Would git "work" in a corrupt worktree whose gitfile is broken, in
> the sense that it notices that the cwd is the top of the working
> tree of a secondary worktree?

No. For this repair to work, the gitfile in the linked worktree must be intact; it must be pointing back at the .git/worktrees/<id> directory so that "git worktree repair" can repair the corresponding .git/worktrees/<id>/gitdir file.

Making it "work" for the case when both the worktree's gitfile is broken and .git/worktrees/<id>/gitdir is broken would require an enhancement like what you mentioned in your review of patch [2/5] in which the user would manually specify the location of the main worktree (or repository). That is something which can be added, but I wanted to keep this initial implementation simple.

Show 6 quoted lines
> Hmph, if the secondary is _moved_, how would "worktree repair $path"
> would know which <id> the $path corresponds to? Would we just cull
> all the <id> that do not point at working secondary worktrees and
> add the $path as if it were a new one by allocating a new <id>, or
> reusing a randomly chosen <id> that points at a non-existing
> location?

Since this can only work if the linked worktree's gitfile is intact, and since the content of the gitfile is the path .git/worktrees/<id>, "git worktree repair" knows the exact <id>, thus the precise .git/worktrees/<id>/gitdir file to repair. It is deterministic; there is no guessing about <id>, and there is no creating a new <id> magically (though I did consider additional repair cases but opted against them for the initial implementation).

Previous: Junio C HamanoNext: Junio C Hamano
Message 12 of 22 in “add "git worktree repair" command”
  1. 0/5 add "git worktree repair" commandEric Sunshine, Aug 27, 2020
  2. 1/5 worktree: add skeleton "repair" commandEric Sunshine, Aug 27, 2020
  3. Junio C HamanoAug 27, 2020
  4. Eric SunshineAug 27, 2020
  5. 5/5 init: make --separate-git-dir work from within linked worktreeEric Sunshine, Aug 27, 2020
  6. 4/5 init: teach --separate-git-dir to repair linked worktreesEric Sunshine, Aug 27, 2020
  7. 2/5 worktree: teach "repair" to fix worktree back-links to main worktreeEric Sunshine, Aug 27, 2020
  8. Junio C HamanoAug 27, 2020
  9. Eric SunshineAug 30, 2020
  10. 3/5 worktree: teach "repair" to fix outgoing links to worktreesEric Sunshine, Aug 27, 2020
  11. Junio C HamanoAug 27, 2020
  12. Eric SunshineAug 30, 2020
  13. Junio C HamanoAug 31, 2020
  14. Johannes SchindelinAug 28, 2020
  15. Eric SunshineAug 28, 2020
  16. 0/5 add "git worktree repair" commandEric Sunshine, Aug 31, 2020
  17. 1/5 worktree: add skeleton "repair" commandEric Sunshine, Aug 31, 2020
  18. 3/5 worktree: teach "repair" to fix outgoing links to worktreesEric Sunshine, Aug 31, 2020
  19. 5/5 init: make --separate-git-dir work from within linked worktreeEric Sunshine, Aug 31, 2020
  20. 2/5 worktree: teach "repair" to fix worktree back-links to main worktreeEric Sunshine, Aug 31, 2020
  21. 4/5 init: teach --separate-git-dir to repair linked worktreesEric Sunshine, Aug 31, 2020
  22. Junio C HamanoAug 31, 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.