threads / discuss / 44251

Feature request: use relative path in worktree config files

Subject: Feature request: use relative path in worktree config files

## tl;dr

8 messages between Oct 8, 2016 and Oct 11, 2016.

replies: 7people: 3as markdown or json

Stéphane Klein· Oct 8, 2016, 09:35 UTC · lore
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· Oct 8, 2016, 19:54 UTC · re: Stéphane Klein · lore

Re: Feature request: use relative path in worktree config files

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>:
Show 25 quoted lines
> 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· Oct 9, 2016, 11:11 UTC · re: Stéphane Klein · lore

Re: Feature request: use relative path in worktree config files

On Sat, Oct 8, 2016 at 4:35 PM, Stéphane Klein <contact@stephane-klein.info> wrote:

Show 10 quoted lines
> 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.

Show 5 quoted lines
> 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· Oct 9, 2016, 11:22 UTC · re: Duy Nguyen · lore

Re: Feature request: use relative path in worktree config files

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.
Show 11 quoted lines
>
>> 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· Oct 9, 2016, 11:37 UTC · re: Stéphane Klein · lore

Re: Feature request: use relative path in worktree config files

On Sun, Oct 9, 2016 at 6:22 PM, Stéphane Klein <contact@stephane-klein.info> wrote:

Show 8 quoted lines
> 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.

Show 19 quoted lines
>>> 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· Oct 9, 2016, 11:39 UTC · re: Duy Nguyen · lore

Re: Feature request: use relative path in worktree config files

2016-10-09 13:37 GMT+02:00 Duy Nguyen <pclouds@gmail.com>:
Show 24 quoted lines
> 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· Oct 10, 2016, 18:36 UTC · re: Duy Nguyen · lore

Re: Feature request: use relative path in worktree config files

Duy Nguyen <pclouds@gmail.com> writes:
Show 8 quoted lines
>> 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· Oct 11, 2016, 11:16 UTC · re: Junio C Hamano · lore

Re: Feature request: use relative path in worktree config files

On Tue, Oct 11, 2016 at 1:36 AM, Junio C Hamano <gitster@pobox.com> wrote:
Show 19 quoted lines
> 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.

Show 6 quoted lines
> 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

← back to recent threads