git/list[1] front-page[2] threads[3] people[4] search[5] about
 

Re: [long] worktree setup cases

From
Nguyen Thai Ngoc Duy <pclouds@gmail.com>
Date
Oct 21, 2010, 12:50 UTC
Message-ID
<AANLkTikwApJ2EtJNiOZPHVrz6seJNP-zEqzH_b62ksLf@mail.gmail.com>
In-Reply-To
<20101021033042.GA1891@burratino>
On Thu, Oct 21, 2010 at 10:30 AM, Jonathan Nieder <jrnieder@gmail.com> wrote:
Show 16 quoted lines
> Nguyen Thai Ngoc Duy wrote:
>> On Thu, Oct 21, 2010 at 2:07 AM, Jonathan Nieder <jrnieder@gmail.com> wrote:
>
>>>  - otherwise, if original cwd was under repository,
> [...]
>>>              GIT_WORK_TREE defaults to unset.
>>
>> What do you mean by "under repository"? If the repo is /tmp/git/.git,
>> then cwd is at /tmp/git/.git?
>
> I meant if the original cwd lies within the repository.
>
> Example:
>
>  repo           /tmp/git/.git
>  starting cwd   /tmp/git/.git/objects/pack
OK it's considered a bare repo, so no worktree.
Show 19 quoted lines
>>> D. User-supplied relative paths.
>>>
>>>  - path in .git file is relative to containing directory
>>>  - path in GIT_DIR is relative to original cwd
>>>  - paths in GIT_WORK_TREE and core.worktree are relative to
>>>   $GIT_DIR
>>
>> I think $GIT_WORK_TREE is relative to original cwd.
>
> git.txt is confusing, then.  Actually it has some other insights:
>
>  --work-tree=<path>
>        Set the path to the working tree. The value
>        will not be used in combination with
>        repositories found automatically in a .git
>        directory (i.e. $GIT_DIR is not set).
>
> So GIT_WORK_TREE should be discarded or warned about when GIT_DIR is
> not set. (?)
Yeah. Junio reminded me in another mail. It should warn (at least, me).
Show 7 quoted lines
>        This can also be controlled by setting the
>        GIT_WORK_TREE environment variable and the
>        core.worktree configuration variable. It can be
>        an absolute path or relative path to the
>        directory specified by --git-dir or GIT_DIR.
>
> This is where I got the impression about relative paths.

Hmm.. OK then. So worktree can be relative to gitdir, which in turn can be relative to original cwd. Fun.

Show 14 quoted lines
>        Note: If --git-dir or GIT_DIR are specified but
>        none of --work-tree, GIT_WORK_TREE and
>        core.worktree is specified, the current working
>        directory is regarded as the top directory of
>        your working tree.
>
> Nice to see this case is documented.
>
>> Yes, core.worktree
>> should be relative to $GIT_DIR.
>
> Speaking of which, it is not clear to me that core.worktree should
> fall under the forbidden case discussed above.  If it does, what is
> the point of making it configurable?

I was not the one who introduced core.worktree, so I can't really tell. Maybe less keystrokes? You know, "GIT_DIR=foo.git git foo" is shorter than "GIT_DIR=foo.git GIT_WORK_TREE=/path/to/somewhere git foo". I tend to think that core.worktree is always effective regardless $GIT_DIR env setting. But I was wrong.

Also the "relative to $GIT_DIR" may be confusing. If $GIT_DIR points to a file that points to a true repo, then to which one it is relative?

-- 
Duy
Previous: Jonathan NiederNext: Jonathan Nieder
Message 6 of 17 in “[long] worktree setup cases”
  1. Nguyen Thai Ngoc DuyOct 20, 2010
  2. Jonathan NiederOct 20, 2010
  3. Jonathan NiederOct 20, 2010
  4. Nguyen Thai Ngoc DuyOct 21, 2010
  5. Jonathan NiederOct 21, 2010
  6. Nguyen Thai Ngoc DuyOct 21, 2010
  7. Jonathan NiederOct 21, 2010
  8. Nguyen Thai Ngoc DuyOct 23, 2010
  9. Enrico WeigeltOct 21, 2010
  10. Nguyen Thai Ngoc DuyOct 22, 2010
  11. Enrico WeigeltOct 22, 2010
  12. .git file (Re: [long] worktree setup cases)Jonathan Nieder, Oct 22, 2010
  13. Nguyen Thai Ngoc DuyOct 22, 2010
  14. Junio C HamanoOct 20, 2010
  15. Nguyen Thai Ngoc DuyOct 21, 2010
  16. Enrico WeigeltOct 21, 2010
  17. Junio C HamanoOct 21, 2010

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.