git@vger.kernel.org mailing list mirror (one of many)
 help / color / mirror / code / Atom feed
From: "Ganriel Nützi" <gnuetzi@gmail.com>
To: Eric Sunshine <sunshine@sunshineco.com>
Cc: "Git List" <git@vger.kernel.org>,
	"Nguyễn Thái Ngọc Duy" <pclouds@gmail.com>
Subject: Re: GIT_DIR output from git worktree list
Date: Mon, 7 Dec 2020 08:28:28 +0100	[thread overview]
Message-ID: <A462326B-505D-4A92-B789-21BB8FE6AA16@gmail.com> (raw)
In-Reply-To: <CAPig+cTsEx-puHn1N2=fBVAgdvc7cutCDTC7vBJuLm5utObfJg@mail.gmail.com>

As of your rational, wouldn‘t it be good anyway to have a file „worktree“ inside the .git dir (of the worktree) containing the path to the main worktree? So to speak any worktree always has a .git dir with a back link to its main worktree (the existence of the git dir might pose other problems?) 



Von meinem iPhone gesendet

> Am 07.12.2020 um 05:34 schrieb Eric Sunshine <sunshine@sunshineco.com>:
> 
>> On Wed, Sep 30, 2020 at 1:33 AM Eric Sunshine <sunshine@sunshineco.com> wrote:
>>> 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`.
>> 
>> 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.)
> 
> Fixing this is more complex than it seems at first glance. In fact,
> I'm not sure there is a good fix at present without somehow recording
> the location of the main worktree somewhere.
> 
> The problem is that determining the location of the main worktree by
> consulting --work-tree or GIT_WORK_TREE when listing worktrees would
> only give the desired result when `git worktree list` is run from
> within the main worktree. If it is run within a secondary worktree,
> then neither --work-tree nor GIT_WORK_TREE would be referencing the
> main worktree (at best, they'd be referencing the secondary worktree),
> which means that they would not help in determining the location of
> the main worktree, thus `git worktree list` in a secondary worktree
> would give different output.
> 
> Consulting core.worktree _may_ be doable, but it's iffy and would be
> extra complicated because that configuration value is treated
> specially. In particular, the value of core.worktree of the main
> worktree is intentionally hidden from secondary worktrees. So, while
> it _may_ be possible to write special-purpose code to go and seek out
> the value of core.worktree for the main worktree by manually
> spelunking various configuration files, it would be complicated. In
> fact, it would be doubly complicated because it would require two
> distinct implementations: one for when extensions.worktreeConfig is
> enabled and one for when it is not.
> 
> The fact that the output of `git worktree list` would differ depending
> upon whether it is run in the main worktree or a secondary worktree
> (and whether core.worktree is configured or --work-tree or
> GIT_WORK_TREE is used) makes me quite hesitant about these approaches.
> I worry that such inconsistency would be perceived as instability, as
> well as making it difficult to script `git worktree` reliably.
> 
> So, at present, I think any solution which can produce reliable,
> consistent output may need to record the path of the main worktree
> somewhere, but I haven't thought too deeply yet about how to do that
> cleanly (while also taking other Git implementations into account).

  reply	other threads:[~2020-12-07  7:29 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
2020-12-07  4:34   ` Eric Sunshine
2020-12-07  7:28     ` Ganriel Nützi [this message]
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=A462326B-505D-4A92-B789-21BB8FE6AA16@gmail.com \
    --to=gnuetzi@gmail.com \
    --cc=git@vger.kernel.org \
    --cc=pclouds@gmail.com \
    --cc=sunshine@sunshineco.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).