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

Re: [PATCH] worktree: teach `repair` to fix multi-directional breakage

From
Junio C Hamano <gitster@pobox.com>
Date
Dec 17, 2020, 19:49 UTC
Message-ID
<xmqqwnxgxlfi.fsf@gitster.c.googlers.com>
In-Reply-To
<CAPig+cQT2Cj4i=2kq_svMyKiFmNLxvpa5kG=XNeaT+8UD5238Q@mail.gmail.com>
Eric Sunshine <sunshine@sunshineco.com> writes:
> We only have the paths making the two-way link between the repository
> and the secondary worktrees. Specifically, the outgoing
> <repo>/worktrees/<id>/gitdir points at /path/to/worktree/.git, and the
> incoming /path/to/worktree/.git points at <repo>/worktrees/<id>.
Yes.
Show 6 quoted lines
> The inference is intentionally simple-minded. There is no path-based
> inference or other heuristic at play; the entire inference is based
> upon <id>. The worktree's path is specified as an argument. `git
> worktree repair` manually reads the ".git" gitfile at that location
> and, if it is well-formed, extracts the <id>. It then searches for a
> corresponding <id> in <repo>/worktrees/ and,...

That is exactly the point I got confused. The worktree's path comes as an argument from the user, so we'd trust it. And it has ".git" that is a gitfile that used to point at <repo> but because we are trying to deal with a situation where both worktree and repo moved, it cannot be used to learn where <repo> is. Then, even after learning what <id> to use, how would we know where to use that <id> to find <repo>/worktrees/<id>, when the location of <repo> is unknown?

I think the answer is "where the user starts the 'git worktree' command has to be under control of some repository (perhaps found by a call to setup_git_directory()), and we'd use that one as <repo>".

Since I did not see that (in hindsight an obvious) piece, I failed to see how it could possibly work. But now it is clear.

Thanks.
Previous: Eric SunshineNext: Eric Sunshine
Message 4 of 7 in “worktree: teach `repair` to fix multi-directional breakage”
  1. worktree: teach `repair` to fix multi-directional breakageEric Sunshine, Dec 8, 2020
  2. Junio C HamanoDec 8, 2020
  3. Eric SunshineDec 17, 2020
  4. Junio C HamanoDec 17, 2020
  5. Eric SunshineDec 17, 2020
  6. 0/1 teach `worktree repair` to fix two-way linkageEric Sunshine, Dec 21, 2020
  7. 1/1 worktree: teach `repair` to fix multi-directional breakageEric Sunshine, Dec 21, 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.