# RE: git worktrees must exist even if locked

3 messages from 2017-05-15 to 2017-05-29. Participants: taylor, david, Junio C Hamano, Duy Nguyen.
Thread: https://gitlist.dev/t/45966

## taylor, david, 2017-05-15 13:58

Subject: RE: git worktrees must exist even if locked
Message-ID: <63F1AEE13FAE864586D589C671A6E18B0D6B8C@MX203CL03.corp.emc.com>
URL: https://gitlist.dev/e/63F1AEE13FAE864586D589C671A6E18B0D6B8C%40MX203CL03.corp.emc.com

```
The original report was against Git v2.12.2.  I have since tried v2.12.3, v2.13.0,
and the next branch.  All exhibit the same symptoms.

Even if you ignore the original scenario for creating the problem, if I do a 'rm -rf' or 'mv'
of a tree that contains within it worktrees, that should not break the use of Git with
worktrees that live elsewhere nor commands that don't require a repository.

> -----Original Message-----
> From: taylor, david
> Sent: Wednesday, May 10, 2017 4:25 PM
> To: git@vger.kernel.org
> Subject: git worktrees must exist even if locked
> 
> The Git documentation in describing worktrees says that one reason
> why you might want to lock a worktree is to prevent it from being pruned
> if it is on a removable media that isn't currently mounted.
> 
> So, my expectation was that if the worktree is inaccessible (and locked), Git
> would pretend that there is no worktree by that name.
> 
> In reality, if you have such a worktree, Git gets an error.
> 
>  On local systems, /home is local to a machine; home directories are
> elsewhere.
> Home directories are NFS mounted; /home is not.
> 
> . create a repository in /my/home/dir/my-repo.git with
> 
>     git clone --bare <some arguments>
> 
> . create an empty directory /home/somedir/worktree-tests
> 
> . use 'git worktree add' to add /home/somedir/worktree-tests/<branch-
> name>
>   as a worktree on branch <branch-name>.  It gets populated with the correct
>   content.
> 
> . lock it using'git worktree lock'
> 
> So far, so good.  Now, go to a different computer -- one on which
> /home/somedir/worktree-tests does not exist (and therefore
> /home/somedir/worktree-tests/<branch-name> does not exist).
> 
> . cd /my/home/dir/my-repo.git
> 
> Now, try issuing Git commands.  Many will fail.
> 
>   git fetch ==> fails:
> 
>   fatal: Invalid path '/home/somedir/worktree-tests': No such file or directory
> 
>   git status ==> fails -- same error as above
>   git help worktree ==> fails -- same error as above

```

## Junio C Hamano, 2017-05-15 22:43

Subject: Re: git worktrees must exist even if locked
Message-ID: <xmqqshk568s4.fsf@gitster.mtv.corp.google.com>
URL: https://gitlist.dev/e/xmqqshk568s4.fsf%40gitster.mtv.corp.google.com
In-Reply-To: <63F1AEE13FAE864586D589C671A6E18B0D6B8C@MX203CL03.corp.emc.com>

```
"taylor, david" <David.Taylor@dell.com> writes:

> The original report was against Git v2.12.2.  I have since tried v2.12.3, v2.13.0,
> and the next branch.  All exhibit the same symptoms.
>
> Even if you ignore the original scenario for creating the problem, if I do a 'rm -rf' or 'mv'
> of a tree that contains within it worktrees, that should not break the use of Git with
> worktrees that live elsewhere nor commands that don't require a repository.

Duy, any ideas?

Thanks.

>
>> -----Original Message-----
>> From: taylor, david
>> Sent: Wednesday, May 10, 2017 4:25 PM
>> To: git@vger.kernel.org
>> Subject: git worktrees must exist even if locked
>> 
>> The Git documentation in describing worktrees says that one reason
>> why you might want to lock a worktree is to prevent it from being pruned
>> if it is on a removable media that isn't currently mounted.
>> 
>> So, my expectation was that if the worktree is inaccessible (and locked), Git
>> would pretend that there is no worktree by that name.
>> 
>> In reality, if you have such a worktree, Git gets an error.
>> 
>>  On local systems, /home is local to a machine; home directories are
>> elsewhere.
>> Home directories are NFS mounted; /home is not.
>> 
>> . create a repository in /my/home/dir/my-repo.git with
>> 
>>     git clone --bare <some arguments>
>> 
>> . create an empty directory /home/somedir/worktree-tests
>> 
>> . use 'git worktree add' to add /home/somedir/worktree-tests/<branch-
>> name>
>>   as a worktree on branch <branch-name>.  It gets populated with the correct
>>   content.
>> 
>> . lock it using'git worktree lock'
>> 
>> So far, so good.  Now, go to a different computer -- one on which
>> /home/somedir/worktree-tests does not exist (and therefore
>> /home/somedir/worktree-tests/<branch-name> does not exist).
>> 
>> . cd /my/home/dir/my-repo.git
>> 
>> Now, try issuing Git commands.  Many will fail.
>> 
>>   git fetch ==> fails:
>> 
>>   fatal: Invalid path '/home/somedir/worktree-tests': No such file or directory
>> 
>>   git status ==> fails -- same error as above
>>   git help worktree ==> fails -- same error as above

```

## Duy Nguyen, 2017-05-29 10:17

Subject: Re: git worktrees must exist even if locked
Message-ID: <CACsJy8A691aGfKfa7h1y7A3sgnWgDm_eLA5tj78ES1XjP+mK5Q@mail.gmail.com>
URL: https://gitlist.dev/e/CACsJy8A691aGfKfa7h1y7A3sgnWgDm_eLA5tj78ES1XjP%2BmK5Q%40mail.gmail.com
In-Reply-To: <xmqqshk568s4.fsf@gitster.mtv.corp.google.com>

```
On Tue, May 16, 2017 at 5:43 AM, Junio C Hamano <gitster@pobox.com> wrote:
> "taylor, david" <David.Taylor@dell.com> writes:
>
>> The original report was against Git v2.12.2.  I have since tried v2.12.3, v2.13.0,
>> and the next branch.  All exhibit the same symptoms.
>>
>> Even if you ignore the original scenario for creating the problem, if I do a 'rm -rf' or 'mv'
>> of a tree that contains within it worktrees, that should not break the use of Git with
>> worktrees that live elsewhere nor commands that don't require a repository.
>
> Duy, any ideas?

We are supposed to tolerate missing worktrees if locked. I'm guessing
that lots of changes in get_worktrees() lately may perhaps forget
about this and be too strict on locked worktrees.
-- 
Duy

```
