threads / discuss / 54767

'git worktree repair' can't repair when main and linked worktrees are moved

Subject: 'git worktree repair' can't repair when main and linked worktrees are moved

## tl;dr

5 messages between Dec 4, 2020 and Dec 8, 2020.

replies: 4people: 2as markdown or json

Philippe Blain· Dec 4, 2020, 23:14 UTC · lore
Hello,

I've had to move all my Git clones to a new filesystem. Several of them use secondary worktrees, and all are at the same level ex:

$ ls code git git2 git3 other other2 other3 ...

I had hoped to use the new 'git worktree repair' command but it seems it does not work for this use case.

I tried several things:

( cd git && git repair ) ( cd git && git repair ../git2 ) ( cd git && git repair /old/path/to/old/filesystem/git2 ) ( cd git2 && git repair /old/path/to/old/filesystem/git2 ) ( cd git2 && git repair ../git )

None of them work. Note that /old/path/to/old/filesystem/ does not exist anymore.

Is this supposed to work ? Or it's not something that 'git worktree repair' can currently cope with ?

P.S. I know how to repair the worktrees manuallly, I just wanted to test if 'repair' could help me.

Cheers,
Philippe.
Philippe Blain· Dec 4, 2020, 23:21 UTC · re: Philippe Blain · lore

Re: 'git worktree repair' can't repair when main and linked worktrees are moved

Show 5 quoted lines
> Le 4 déc. 2020 à 18:14, Philippe Blain <levraiphilippeblain@gmail.com> a écrit :
> 
> I tried several things:
> 
> ( cd git && git repair )
Oups, please read 'git worktree repair' here and below.
> ( cd git && git repair ../git2 )
> ( cd git && git repair /old/path/to/old/filesystem/git2 )
> ( cd git2 && git repair /old/path/to/old/filesystem/git2 )
> ( cd git2 && git repair ../git )
Eric Sunshine· Dec 5, 2020, 09:22 UTC · re: Philippe Blain · lore

Re: 'git worktree repair' can't repair when main and linked worktrees are moved

On Fri, Dec 4, 2020 at 6:14 PM Philippe Blain <levraiphilippeblain@gmail.com> wrote:

Show 9 quoted lines
> I've had to move all my Git clones to a new filesystem.
> Several of them use secondary worktrees, and all are
> at the same level ex:
>
> I had hoped to use the new 'git worktree repair' command
> but it seems it does not work for this use case.
>
> Is this supposed to work ? Or it's not something that
> 'git worktree repair' can currently cope with ?

This is a situation which `git worktree repair` can not yet handle. The implementation of bare bones `git worktree repair` was sufficiently complex that I decided that additional cases like this and other bells and whistles should be built later atop the basic implementation. At present, only the following cases are handled:

* secondary worktree has moved so main worktree doesn't know where it
is, but secondary worktree still knows where main worktree is, thus
`git worktree repair` within the secondary can contact the main and
fix up main's reference to the secondary
* main worktree has moved so secondary worktrees don't know where it
is, but main worktree still knows where secondary worktrees are, thus
`git worktree repair` within main can contact each secondary and fix
up their references back to main

There was a little discussion during review[1,2,3] about how the situation might be handled in which both main and secondary worktrees have been moved. Primarily, a new command-line option would be added allowing the user to tell `git worktree repair` where the main worktree is, in addition to also giving the paths to the secondary worktrees as arguments (the latter of which is already supported). Now that I'm thinking about it, I realize also that if invoked in the main worktree, then `git worktree repair` can recognize that it is operating in the main worktree (and infer the value of the new command-line option for specifying location of the main worktree), thus the user would only have to supply paths to the secondary worktrees as arguments. My main concern with inferring too much automatically is that the command could be used to hijack a worktree belonging to another repository (but perhaps that's a case of "don't do it if it hurts").

Of course, we could also get more fancy and provide some way to specify path transformations. For instance, `git worktree repair --map-path=/old/path:/new/path` might make it possible to repair links in both directions by applying the path transformation to the paths involved in the repair. However, this idea is barely germinated; it's far less well thought out than the previous one.

[1]: https://lore.kernel.org/git/CAPig+cT-w6LV490MGNyG_ihWkSzdgfnEBrjQCsafjndTRmMgFA@mail.gmail.com/ [2]: https://lore.kernel.org/git/xmqqlfi0qaru.fsf@gitster.c.googlers.com/ [3]: https://lore.kernel.org/git/CAPig+cT-ipENZQ39wpaGukRzx3d52OatKEXjWc3_mv56jMbDRg@mail.gmail.com/

Eric Sunshine· Dec 8, 2020, 17:42 UTC · re: Eric Sunshine · lore

Re: 'git worktree repair' can't repair when main and linked worktrees are moved

On Sat, Dec 5, 2020 at 4:22 AM Eric Sunshine <sunshine@sunshineco.com> wrote:
Show 8 quoted lines
> On Fri, Dec 4, 2020 at 6:14 PM Philippe Blain
> <levraiphilippeblain@gmail.com> wrote:
> > I've had to move all my Git clones to a new filesystem.
> > Several of them use secondary worktrees [...]
> > I had hoped to use the new 'git worktree repair' command
> > but it seems it does not work for this use case.
>
> This is a situation which `git worktree repair` can not yet handle.
A patch[1] addressing this shortcoming has been posted.
[1]: https://lore.kernel.org/git/20201208173705.5770-1-sunshine@sunshineco.com/
Philippe Blain· Dec 8, 2020, 22:27 UTC · re: Eric Sunshine · lore

Re: 'git worktree repair' can't repair when main and linked worktrees are moved

Hi Eric,

Le mar. 8 déc. 2020, à 12 h 42, Eric Sunshine <sunshine@sunshineco.com> a écrit :

Show 14 quoted lines
>
> On Sat, Dec 5, 2020 at 4:22 AM Eric Sunshine <sunshine@sunshineco.com> wrote:
> > On Fri, Dec 4, 2020 at 6:14 PM Philippe Blain
> > <levraiphilippeblain@gmail.com> wrote:
> > > I've had to move all my Git clones to a new filesystem.
> > > Several of them use secondary worktrees [...]
> > > I had hoped to use the new 'git worktree repair' command
> > > but it seems it does not work for this use case.
> >
> > This is a situation which `git worktree repair` can not yet handle.
>
> A patch[1] addressing this shortcoming has been posted.
>
> [1]: https://lore.kernel.org/git/20201208173705.5770-1-sunshine@sunshineco.com/
Great! I'll try to take a look.

Thanks, Philippe.

← back to recent threads