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

Re: GIT_DIR output from git worktree list

From
Gabriel Nützi <gnuetzi@gmail.com>
Date
Sep 30, 2020, 07:34 UTC
Message-ID
<335b6e6a-9527-5444-da80-08faf43db606@gmail.com>
In-Reply-To
<CAPig+cTwNwt+_f4FYDqy5xVsDVU3pqfKXtK6GKtWLLqbU6Y8Vg@mail.gmail.com>
Am 30.09.2020 um 07:33 schrieb Eric Sunshine:
Show 18 quoted lines
> On Tue, Sep 29, 2020 at 1:31 PM Gabriel Nützi <gnuetzi@gmail.com> wrote:
>> When you do move the .git folder somewhere else:
>>
>> git init Test && cd Test && mv .git .git-b
>> git --git-dir=.git-b --work-tree . worktree list
>>
>> the output is :
>> ..../Test/.git-b  0000000 [master]
>>
>> Why is the output a .git Dir and not a worktree. I expected `.../Test`.
> Because the implementation doesn't really look for or know where the
> main worktree is. Instead, it's taking the path of the repository and
> stripping off "/.git" if present, and reporting that as the main
> worktree. Under normal circumstances this works just fine because
> either (a) the repository _is_ the .git directory within the main
> worktree, or (b) it's a bare repository and there is no main worktree,
> thus it reports the repository path instead of the non-existent main
> worktree.

Ok, it's kind of sad that as far as I understood, there is probably always only this heuristic about stripping ".git" because the main worktree path is not registered inside the .git dir or somewhere else. I mean you can technically name the git directory what ever you want and in that case how is that stripping than going to work? But of course when you do so, you probably need to set either GIT_DIR, or or use --git-dir

Also what I realized is, isn't the doc a bit inexact about GIT_DIR:
> GIT_DIR is the location of the .git folder.
Shouldn't it read: GIT_DIR is the path of the .git folder. Location could mean its the parent folder? Hm...
Show 5 quoted lines
> I suppose one way to fix this would be to specially check if
> --work-tree or GIT_WORK_TREE is specified and use that value as the
> path of the main worktree. (This special case would only be used when
> computing the main worktree path; it would not be used when computing
> linked worktree paths.)
Probably, --work-tree, GIT_WORK_TREE or core.worktree.

Thanks Eric! BR

Previous: Eric SunshineNext: Eric Sunshine
Message 3 of 9 in “GIT_DIR output from git worktree list”
  1. Gabriel NütziSep 29, 2020
  2. Eric SunshineSep 30, 2020
  3. Gabriel NütziSep 30, 2020
  4. Eric SunshineSep 30, 2020
  5. Eric SunshineDec 7, 2020
  6. Ganriel NütziDec 7, 2020
  7. Eric SunshineDec 8, 2020
  8. Duy NguyenDec 9, 2020
  9. Eric SunshineDec 13, 2020

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.