Re: GIT_DIR output from git worktree list
- From
Eric Sunshine <sunshine@sunshineco.com>
- Date
- Sep 30, 2020, 05:33 UTC
- Message-ID
- <CAPig+cTwNwt+_f4FYDqy5xVsDVU3pqfKXtK6GKtWLLqbU6Y8Vg@mail.gmail.com>
- In-Reply-To
- <CAA9rTudStQOK7kRa6jYJHE3D3grnFF3idQe65h9t6oJB30xa1A@mail.gmail.com>
On Tue, Sep 29, 2020 at 1:31 PM Gabriel Nützi <gnuetzi@gmail.com> wrote:
Show 9 quoted lines
> 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.
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.)