From: Jeff King <peff@peff.net>
To: "Nguyễn Thái Ngọc Duy" <pclouds@gmail.com>
Cc: git@vger.kernel.org, snoksrud@gmail.com
Subject: Re: [PATCH] setup: set env $GIT_WORK_TREE when work tree is set, like $GIT_DIR
Date: Fri, 26 Jun 2015 07:56:03 -0400 [thread overview]
Message-ID: <20150626115603.GB4315@peff.net> (raw)
In-Reply-To: <1435315055-27011-1-git-send-email-pclouds@gmail.com>
On Fri, Jun 26, 2015 at 05:37:35PM +0700, Nguyễn Thái Ngọc Duy wrote:
> This is where the "fun" is. The legacy behavior is, if $GIT_WORK_TREE is
> not set but $GIT_DIR is, cwd is chosen as worktree's top. If you happen
> to stand at worktree's top when you do this, all is well. If you are in
> a subdir "foo/bar" (real worktree's top is "foo"), this behavior bites
> you: your detected worktree is now "foo/bar", but the first run
> correctly detected worktree as "foo". You get "internal error: work tree
> has already been set" as a result.
I think this makes sense. I feel like we've dealt with this before, but
the two previous rounds I found were basically:
- we have GIT_IMPLICIT_WORK_TREE, but that is for the _opposite_ case.
I.e., when we do not have a work tree and must communicate so to
later code (including sub-processes).
- a discussion about switching the "work tree defaults to '.' when
$GIT_DIR is set" behavior yielded almost the identical patch:
http://article.gmane.org/gmane.comp.version-control.git/219196
but we were so wrapped up in the greater discussion we did not apply
that simple fix. :)
> Bottom line is, when $GIT_DIR is set, $GIT_WORK_TREE should be set too
> unless there's no work tree. But setting $GIT_WORK_TREE inside
> set_git_dir() may backfire. We don't know at that point if work tree is
> already configured by the caller. So set it when work tree is
> detected. It does not harm if $GIT_WORK_TREE is set while $GIT_DIR is
> not.
Yeah, it would be nicer if we could make sure we always set
GIT_WORK_TREE along with GIT_DIR (since anything else is potentially
dangerous), but I don't think it's feasible to do it in set_git_dir for
the reasons you state.
I gave a quick peek through setup_explicit_git_dir to see if we missed
other cases (spoiler: no):
- if we have core.bare set, we set $GIT_DIR without setting the
working tree. But that's OK, because we'll never look at
$GIT_WORK_TREE in that case. Good.
- if we have core.worktree set, then we call set_git_work_tree to
match. Good.
- If GIT_IMPLICIT_WORK_TREE is turned off, we set_git_dir but do not
set GIT_WORK_TREE. Good, because otherwise it would take precedence.
- there are some more calls to set_git_dir at the end, but I think in
those cases we will already have set up the working tree (or decided
we do not have one, by the above logic).
So that all seems fine. We also call set_git_dir from enter_repo, but in
that case we have already moved into the .git directory itself, so that
is OK. setup_discovered_git_dir also makes some calls, but either we are
explicitly bare there, or we call set_git_work_tree(".").
So I do not see any cases that will regress, or that are uncovered. Of
course, that is just from reading the code. Getting one million monkeys
to bang on the keyboard may turn up any real problems. :)
> + if (setenv(GIT_WORK_TREE_ENVIRONMENT, work_tree, 1))
> + error("Could not set GIT_WORK_TREE to '%s'", work_tree);
Should this be die()? setenv() should basically never fail, but if it
does, it could be confusing and/or dangerous to run without the variable
set.
-Peff
next prev parent reply other threads:[~2015-06-26 11:56 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2015-06-25 14:15 Linked workdirs break typo-correction Bjørnar Snoksrud
2015-06-26 10:37 ` [PATCH] setup: set env $GIT_WORK_TREE when work tree is set, like $GIT_DIR Nguyễn Thái Ngọc Duy
2015-06-26 11:56 ` Jeff King [this message]
2015-06-27 5:57 ` Duy Nguyen
2015-06-26 17:15 ` Junio C Hamano
2015-06-26 19:02 ` Junio C Hamano
2015-06-26 17:30 ` Junio C Hamano
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
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20150626115603.GB4315@peff.net \
--to=peff@peff.net \
--cc=git@vger.kernel.org \
--cc=pclouds@gmail.com \
--cc=snoksrud@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.
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 NNTP newsgroup(s).