git@vger.kernel.org mailing list mirror (one of many)
 help / color / mirror / code / Atom feed
From: Eric Sunshine <sunshine@sunshineco.com>
To: "Gabriel Nützi" <gnuetzi@gmail.com>
Cc: Git List <git@vger.kernel.org>
Subject: Re: GIT_DIR output from git worktree list
Date: Wed, 30 Sep 2020 16:35:31 -0400	[thread overview]
Message-ID: <CAPig+cSzVVdiH62Gc-ww56OFfPh4-2+3_paWEJf085TgC=nNvg@mail.gmail.com> (raw)
In-Reply-To: <335b6e6a-9527-5444-da80-08faf43db606@gmail.com>

On Wed, Sep 30, 2020 at 3:34 AM Gabriel Nützi <gnuetzi@gmail.com> wrote:
> Am 30.09.2020 um 07:33 schrieb Eric Sunshine:
> > 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. [...]
>
> 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.

This is, of course, an artifact of Git's history. While Git itself is
reasonably old at this point, linked worktrees are a relatively recent
invention, and there had never been a reason to record the path of the
main worktree anywhere. Also, not recording the path allows the
project directory to be relocated easily if needed.

> 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

I don't think it's accurate to say that "you can technically name the
git directory what ever you want". The only _blessed_ name for that
directory is `.git/` if you expect any sort of automatic behavior
regarding repository discovery and determination of the top level of a
worktree.

Certainly, you're free to locate the repository elsewhere -- or name
it something else -- but when you do so, you knowingly give up the
convenience of the automatic behaviors, and instead have to rely upon
--git-dir, GIT_DIR and --worktree, GIT_WORK_TREE, and core.worktree,
which is why those exist.

(Rather than --git-dir, --git-work-tree and cousins, you could also
place a "gitfile" named `.git` in the main worktree referencing the
actual repository path, and by doing so regain all the automatic
behaviors. Alternately, `git init --separate-git-dir` could set this
up for you.)

At any rate, the above comments aside, as mentioned previously, a way
forward might be to teach git-worktree to consult --work-tree,
GIT_WORK_TREE, core.worktree when computing the path of the main
worktree. The fact that it doesn't yet do so is merely an oversight, I
think; one of the several such oversights during initial development,
some of which have already been corrected.

> 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...

That might indeed be an improvement. Perhaps submit a patch making
this change?

  reply	other threads:[~2020-09-30 20:36 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-09-29 17:30 GIT_DIR output from git worktree list Gabriel Nützi
2020-09-30  5:33 ` Eric Sunshine
2020-09-30  7:34   ` Gabriel Nützi
2020-09-30 20:35     ` Eric Sunshine [this message]
2020-12-07  4:34   ` Eric Sunshine
2020-12-07  7:28     ` Ganriel Nützi
2020-12-08 19:27       ` Eric Sunshine
2020-12-09  9:30         ` Duy Nguyen
2020-12-13  6:07           ` Eric Sunshine

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: http://vger.kernel.org/majordomo-info.html

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to='CAPig+cSzVVdiH62Gc-ww56OFfPh4-2+3_paWEJf085TgC=nNvg@mail.gmail.com' \
    --to=sunshine@sunshineco.com \
    --cc=git@vger.kernel.org \
    --cc=gnuetzi@gmail.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://80x24.org/mirrors/git.git

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 read-only IMAP folder(s) and NNTP newsgroup(s).