Re: [PATCH] worktree: teach `repair` to fix multi-directional breakage
- From
Eric Sunshine <sunshine@sunshineco.com>
- Date
- Dec 17, 2020, 20:02 UTC
- Message-ID
- <CAPig+cTpdp4fbzBo9ZWt85O_6e7q5br7CnsBp_ZwJLo02LOjcw@mail.gmail.com>
- In-Reply-To
- <xmqqwnxgxlfi.fsf@gitster.c.googlers.com>
On Thu, Dec 17, 2020 at 2:49 PM Junio C Hamano <gitster@pobox.com> wrote:
Show 19 quoted lines
> Eric Sunshine <sunshine@sunshineco.com> writes: > > 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>".
Correct. This is why the documentation update:
If both the main working tree and linked working trees have been
moved manually, then running `repair` in the main working tree and
specifying the new `<path>` of each linked working tree will
reestablish all connections in both directions.says explicitly that `git worktree repair` must be run in the main worktree for this particular case. (For a bare repository, the command would be run in the bare repository instead, but I omitted that bit to avoid bogging down the documentation, and because the couple preceding paragraphs already mention the bare repository case, so I figured the reader would understand.)
I could also have mentioned in the commit message the requirement of running `git worktree repair` in the main worktree (or bare repo), but didn't want to repeat what the patch itself was already saying. But I think I'll update the commit message to mention it when re-rolling since it's important information for understanding how the repair works.