git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* Feature request: use relative path in worktree config files
@ 2016-10-08  9:35 Stéphane Klein
  2016-10-08 19:54 ` Stéphane Klein
  2016-10-09 11:11 ` Duy Nguyen
  0 siblings, 2 replies; 8+ messages in thread
From: Stéphane Klein @ 2016-10-08  9:35 UTC (permalink / raw)
  To: git

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

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: Feature request: use relative path in worktree config files
  2016-10-08  9:35 Feature request: use relative path in worktree config files Stéphane Klein
@ 2016-10-08 19:54 ` Stéphane Klein
  2016-10-09 11:11 ` Duy Nguyen
  1 sibling, 0 replies; 8+ messages in thread
From: Stéphane Klein @ 2016-10-08 19:54 UTC (permalink / raw)
  To: git

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

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: Feature request: use relative path in worktree config files
  2016-10-08  9:35 Feature request: use relative path in worktree config files Stéphane Klein
  2016-10-08 19:54 ` Stéphane Klein
@ 2016-10-09 11:11 ` Duy Nguyen
  2016-10-09 11:22   ` Stéphane Klein
  1 sibling, 1 reply; 8+ messages in thread
From: Duy Nguyen @ 2016-10-09 11:11 UTC (permalink / raw)
  To: Stéphane Klein; +Cc: Git Mailing List

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

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: Feature request: use relative path in worktree config files
  2016-10-09 11:11 ` Duy Nguyen
@ 2016-10-09 11:22   ` Stéphane Klein
  2016-10-09 11:37     ` Duy Nguyen
  0 siblings, 1 reply; 8+ messages in thread
From: Stéphane Klein @ 2016-10-09 11:22 UTC (permalink / raw)
  To: Duy Nguyen; +Cc: Git Mailing List

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

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: Feature request: use relative path in worktree config files
  2016-10-09 11:22   ` Stéphane Klein
@ 2016-10-09 11:37     ` Duy Nguyen
  2016-10-09 11:39       ` Stéphane Klein
  2016-10-10 18:36       ` Junio C Hamano
  0 siblings, 2 replies; 8+ messages in thread
From: Duy Nguyen @ 2016-10-09 11:37 UTC (permalink / raw)
  To: Stéphane Klein; +Cc: Git Mailing List

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

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: Feature request: use relative path in worktree config files
  2016-10-09 11:37     ` Duy Nguyen
@ 2016-10-09 11:39       ` Stéphane Klein
  2016-10-10 18:36       ` Junio C Hamano
  1 sibling, 0 replies; 8+ messages in thread
From: Stéphane Klein @ 2016-10-09 11:39 UTC (permalink / raw)
  To: Duy Nguyen; +Cc: Git Mailing List

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 :)

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: Feature request: use relative path in worktree config files
  2016-10-09 11:37     ` Duy Nguyen
  2016-10-09 11:39       ` Stéphane Klein
@ 2016-10-10 18:36       ` Junio C Hamano
  2016-10-11 11:16         ` Duy Nguyen
  1 sibling, 1 reply; 8+ messages in thread
From: Junio C Hamano @ 2016-10-10 18:36 UTC (permalink / raw)
  To: Duy Nguyen; +Cc: Stéphane Klein, Git Mailing List

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.

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: Feature request: use relative path in worktree config files
  2016-10-10 18:36       ` Junio C Hamano
@ 2016-10-11 11:16         ` Duy Nguyen
  0 siblings, 0 replies; 8+ messages in thread
From: Duy Nguyen @ 2016-10-11 11:16 UTC (permalink / raw)
  To: Junio C Hamano; +Cc: Stéphane Klein, Git Mailing List

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

^ permalink raw reply	[flat|nested] 8+ messages in thread

end of thread, other threads:[~2016-10-11 11:18 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2016-10-08  9:35 Feature request: use relative path in worktree config files Stéphane Klein
2016-10-08 19:54 ` Stéphane Klein
2016-10-09 11:11 ` Duy Nguyen
2016-10-09 11:22   ` Stéphane Klein
2016-10-09 11:37     ` Duy Nguyen
2016-10-09 11:39       ` Stéphane Klein
2016-10-10 18:36       ` Junio C Hamano
2016-10-11 11:16         ` Duy Nguyen

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).