# Feature request: use relative path in worktree config files

8 messages from 2016-10-08 to 2016-10-11. Participants: Stéphane Klein, Duy Nguyen, Junio C Hamano.
Thread: https://gitlist.dev/t/44251

## Stéphane Klein, 2016-10-08 09:35

Subject: Feature request: use relative path in worktree config files
Message-ID: <CADKxhpe3S4L9CPV9yxh2yhrtJMa9wyZAPC45u_S=RiuzY1Xrkg@mail.gmail.com>
URL: https://gitlist.dev/e/CADKxhpe3S4L9CPV9yxh2yhrtJMa9wyZAPC45u_S%3DRiuzY1Xrkg%40mail.gmail.com

```
Hi,

"git worktree add" write absolute path in ".git/gitdir"

The code source is here
https://git.kernel.org/cgit/git/git.git/tree/builtin/worktree.c?h=v2.10.1#n256

Is it possible to use relative path in this config files:

* [main_worktree]/.git/worktrees/[worktree_foobar]/gitdir
* [worktree_foobar]/.git

Why:

1. I configure worktree on my host
2. next I use this git working copy in Docker with volume share
3. next I've some git error in Docker because config files use absolute path

Best regards,
Stéphane
-- 
Stéphane Klein <contact@stephane-klein.info>
blog: http://stephane-klein.info
cv : http://cv.stephane-klein.info
Twitter: http://twitter.com/klein_stephane

```

## Stéphane Klein, 2016-10-08 19:54

Subject: Re: Feature request: use relative path in worktree config files
Message-ID: <CADKxhpcKOX4RkpbkA8t_6MUh3DttPgwA-YquMkuHkS3C2FR6xg@mail.gmail.com>
URL: https://gitlist.dev/e/CADKxhpcKOX4RkpbkA8t_6MUh3DttPgwA-YquMkuHkS3C2FR6xg%40mail.gmail.com
In-Reply-To: <CADKxhpe3S4L9CPV9yxh2yhrtJMa9wyZAPC45u_S=RiuzY1Xrkg@mail.gmail.com>

```
I've write a small tool in Golang to fix this issue:
https://github.com/harobed/fix-git-worktree

2016-10-08 11:35 GMT+02:00 Stéphane Klein <contact@stephane-klein.info>:
> Hi,
>
> "git worktree add" write absolute path in ".git/gitdir"
>
> The code source is here
> https://git.kernel.org/cgit/git/git.git/tree/builtin/worktree.c?h=v2.10.1#n256
>
> Is it possible to use relative path in this config files:
>
> * [main_worktree]/.git/worktrees/[worktree_foobar]/gitdir
> * [worktree_foobar]/.git
>
> Why:
>
> 1. I configure worktree on my host
> 2. next I use this git working copy in Docker with volume share
> 3. next I've some git error in Docker because config files use absolute path
>
> Best regards,
> Stéphane
> --
> Stéphane Klein <contact@stephane-klein.info>
> blog: http://stephane-klein.info
> cv : http://cv.stephane-klein.info
> Twitter: http://twitter.com/klein_stephane



-- 
Stéphane Klein <contact@stephane-klein.info>
blog: http://stephane-klein.info
cv : http://cv.stephane-klein.info
Twitter: http://twitter.com/klein_stephane

```

## Duy Nguyen, 2016-10-09 11:11

Subject: Re: Feature request: use relative path in worktree config files
Message-ID: <CACsJy8C0kyKor4gCLSJrreRCazazbexvaSdbBg+Cka=-beZU_g@mail.gmail.com>
URL: https://gitlist.dev/e/CACsJy8C0kyKor4gCLSJrreRCazazbexvaSdbBg%2BCka%3D-beZU_g%40mail.gmail.com
In-Reply-To: <CADKxhpe3S4L9CPV9yxh2yhrtJMa9wyZAPC45u_S=RiuzY1Xrkg@mail.gmail.com>

```
On Sat, Oct 8, 2016 at 4:35 PM, Stéphane Klein
<contact@stephane-klein.info> wrote:
> Hi,
>
> "git worktree add" write absolute path in ".git/gitdir"
>
> The code source is here
> https://git.kernel.org/cgit/git/git.git/tree/builtin/worktree.c?h=v2.10.1#n256
>
> Is it possible to use relative path in this config files:
>
> * [main_worktree]/.git/worktrees/[worktree_foobar]/gitdir

The problem with relative is the question "relative to where" and the
answer has to be the same when asked from any worktree. For this file,
it may be ok after we find a good anchor point (which I have avoided
because it gives me headache and absolute paths just work).

> * [worktree_foobar]/.git

This is made absolute on purpose. So that if you move worktree_foobar
away manually, it can still point back to
"[main_worktree]/.git/worktrees/[woktree_foobar]". I'm not sure if we
want relative paths here.

> Why:
>
> 1. I configure worktree on my host
> 2. next I use this git working copy in Docker with volume share
> 3. next I've some git error in Docker because config files use absolute path

I think the common way of dealing with this in docker is put things in
the same path where it actually is outside docker. If you have stuff
at /path/to/foo, then you create the same /path/to/foo inside docker
and bind the data to that path. Does that work?
-- 
Duy

```

## Stéphane Klein, 2016-10-09 11:22

Subject: Re: Feature request: use relative path in worktree config files
Message-ID: <CADKxhpd-gDczp05Ny6wP57RXafWWCimArfA9ki2phh+-gHez4A@mail.gmail.com>
URL: https://gitlist.dev/e/CADKxhpd-gDczp05Ny6wP57RXafWWCimArfA9ki2phh%2B-gHez4A%40mail.gmail.com
In-Reply-To: <CACsJy8C0kyKor4gCLSJrreRCazazbexvaSdbBg+Cka=-beZU_g@mail.gmail.com>

```
2016-10-09 13:11 GMT+02:00 Duy Nguyen <pclouds@gmail.com>:

>> * [worktree_foobar]/.git
> This is made absolute on purpose. So that if you move worktree_foobar
> away manually, it can still point back to
> "[main_worktree]/.git/worktrees/[woktree_foobar]".

Same problem if you move origin git repository.

>
>> Why:
>>
>> 1. I configure worktree on my host
>> 2. next I use this git working copy in Docker with volume share
>> 3. next I've some git error in Docker because config files use absolute path
>
> I think the common way of dealing with this in docker is put things in
> the same path where it actually is outside docker. If you have stuff
> at /path/to/foo, then you create the same /path/to/foo inside docker
> and bind the data to that path. Does that work?

It's not always possible. I can't in my project.

I think there are some pros and some cons for relative path and absolute path.
Maybe append a "--relative" option with `git worktree add` ?

I've converted all path to relative and all work with success.

What do you think to append this --relative option.

Best regards,
Stéphane

```

## Duy Nguyen, 2016-10-09 11:37

Subject: Re: Feature request: use relative path in worktree config files
Message-ID: <CACsJy8DGvyWz2_VBsEfmDWOPGUGAUhKYhCa1qLEMcOdn83ocSQ@mail.gmail.com>
URL: https://gitlist.dev/e/CACsJy8DGvyWz2_VBsEfmDWOPGUGAUhKYhCa1qLEMcOdn83ocSQ%40mail.gmail.com
In-Reply-To: <CADKxhpd-gDczp05Ny6wP57RXafWWCimArfA9ki2phh+-gHez4A@mail.gmail.com>

```
On Sun, Oct 9, 2016 at 6:22 PM, Stéphane Klein
<contact@stephane-klein.info> wrote:
> 2016-10-09 13:11 GMT+02:00 Duy Nguyen <pclouds@gmail.com>:
>
>>> * [worktree_foobar]/.git
>> This is made absolute on purpose. So that if you move worktree_foobar
>> away manually, it can still point back to
>> "[main_worktree]/.git/worktrees/[woktree_foobar]".
>
> Same problem if you move origin git repository.

We could fix up after moving the origin repository (because "gitdir"
file so far uses absolute paths, so we know where all the worktrees
are). But we have not done that.

>>> Why:
>>>
>>> 1. I configure worktree on my host
>>> 2. next I use this git working copy in Docker with volume share
>>> 3. next I've some git error in Docker because config files use absolute path
>>
>> I think the common way of dealing with this in docker is put things in
>> the same path where it actually is outside docker. If you have stuff
>> at /path/to/foo, then you create the same /path/to/foo inside docker
>> and bind the data to that path. Does that work?
>
> It's not always possible. I can't in my project.
>
> I think there are some pros and some cons for relative path and absolute path.
> Maybe append a "--relative" option with `git worktree add` ?
>
> I've converted all path to relative and all work with success.
>
> What do you think to append this --relative option.

Patches are welcome.
-- 
Duy

```

## Stéphane Klein, 2016-10-09 11:39

Subject: Re: Feature request: use relative path in worktree config files
Message-ID: <CADKxhpft56eu1_m70PGi3FPTeX7bS0L=WSe9yKZfLc94N7LsUA@mail.gmail.com>
URL: https://gitlist.dev/e/CADKxhpft56eu1_m70PGi3FPTeX7bS0L%3DWSe9yKZfLc94N7LsUA%40mail.gmail.com
In-Reply-To: <CACsJy8DGvyWz2_VBsEfmDWOPGUGAUhKYhCa1qLEMcOdn83ocSQ@mail.gmail.com>

```
2016-10-09 13:37 GMT+02:00 Duy Nguyen <pclouds@gmail.com>:
> On Sun, Oct 9, 2016 at 6:22 PM, Stéphane Klein
> <contact@stephane-klein.info> wrote:
>> 2016-10-09 13:11 GMT+02:00 Duy Nguyen <pclouds@gmail.com>:
>>>> Why:
>>>>
>>>> 1. I configure worktree on my host
>>>> 2. next I use this git working copy in Docker with volume share
>>>> 3. next I've some git error in Docker because config files use absolute path
>>>
>>> I think the common way of dealing with this in docker is put things in
>>> the same path where it actually is outside docker. If you have stuff
>>> at /path/to/foo, then you create the same /path/to/foo inside docker
>>> and bind the data to that path. Does that work?
>>
>> It's not always possible. I can't in my project.
>>
>> I think there are some pros and some cons for relative path and absolute path.
>> Maybe append a "--relative" option with `git worktree add` ?
>>
>> I've converted all path to relative and all work with success.
>>
>> What do you think to append this --relative option.
>
> Patches are welcome.

Thanks :)

```

## Junio C Hamano, 2016-10-10 18:36

Subject: Re: Feature request: use relative path in worktree config files
Message-ID: <xmqq60p0f3un.fsf@gitster.mtv.corp.google.com>
URL: https://gitlist.dev/e/xmqq60p0f3un.fsf%40gitster.mtv.corp.google.com
In-Reply-To: <CACsJy8DGvyWz2_VBsEfmDWOPGUGAUhKYhCa1qLEMcOdn83ocSQ@mail.gmail.com>

```
Duy Nguyen <pclouds@gmail.com> writes:

>> I think there are some pros and some cons for relative path and absolute path.
>> Maybe append a "--relative" option with `git worktree add` ?
>>
>> I've converted all path to relative and all work with success.
>>
>> What do you think to append this --relative option.
>
> Patches are welcome.

Hmm, are they really welcome? 

Is an invocation of "git worktree add" really the right point in the
workflow to decide if these references to other repositories should
be relative or absolute?  When you are moving referrer, it is more
convenient if the reference uses absolute path to name the
referrent.  When you are moving both referrer and referrent, it is
more convenient to use relative.  

I somehow doubt that users know which future move they would be
making when doing "git worktree add".

To me, this almost looks like a need for a new subcommand to "git
worktree" that lets you move existing worktree to elsewhere, or turn
absolute reference to relative and vice versa.

```

## Duy Nguyen, 2016-10-11 11:16

Subject: Re: Feature request: use relative path in worktree config files
Message-ID: <CACsJy8AZVWNQNgsw21EF2UOk42oFeyHSRntw_rpeZz_OT1xdMw@mail.gmail.com>
URL: https://gitlist.dev/e/CACsJy8AZVWNQNgsw21EF2UOk42oFeyHSRntw_rpeZz_OT1xdMw%40mail.gmail.com
In-Reply-To: <xmqq60p0f3un.fsf@gitster.mtv.corp.google.com>

```
On Tue, Oct 11, 2016 at 1:36 AM, Junio C Hamano <gitster@pobox.com> wrote:
> Duy Nguyen <pclouds@gmail.com> writes:
>
>>> I think there are some pros and some cons for relative path and absolute path.
>>> Maybe append a "--relative" option with `git worktree add` ?
>>>
>>> I've converted all path to relative and all work with success.
>>>
>>> What do you think to append this --relative option.
>>
>> Patches are welcome.
>
> Hmm, are they really welcome?
>
> Is an invocation of "git worktree add" really the right point in the
> workflow to decide if these references to other repositories should
> be relative or absolute?  When you are moving referrer, it is more
> convenient if the reference uses absolute path to name the
> referrent.  When you are moving both referrer and referrent, it is
> more convenient to use relative.

You're right (thanks for thinking this through). There's another case
that benefits from relative paths besides Stephane's use case: if you
put the entire repo and all associated worktrees on a portable disk,
the disk could be mounted on different paths each time, so absolute
paths do not fly.

> I somehow doubt that users know which future move they would be
> making when doing "git worktree add".
>
> To me, this almost looks like a need for a new subcommand to "git
> worktree" that lets you move existing worktree to elsewhere, or turn
> absolute reference to relative and vice versa.

An alternative is always use relative paths. You have to move
worktrees with "git worktree move". Which simplifies things a bit
(absolute -> relative conversion on existing worktrees could be done
at move time). But I'm not sure if it's a good idea to kill manual
move support. If you accidentally move a worktree, it'll be
disconnected and you have to fix that by yourself.
-- 
Duy

```
