From: Jeff King <peff@peff.net>
To: Junio C Hamano <gitster@pobox.com>
Cc: John Keeping <john@keeping.me.uk>, Elliott Cable <me@ell.io>,
git@vger.kernel.org
Subject: Re: `git rev-parse --is-inside-work-tree` and $GIT_WORK_TREE
Date: Tue, 29 Mar 2016 16:26:27 -0400 [thread overview]
Message-ID: <20160329202626.GC9527@sigill.intra.peff.net> (raw)
In-Reply-To: <xmqq60w5xdl2.fsf@gitster.mtv.corp.google.com>
On Tue, Mar 29, 2016 at 12:56:41PM -0700, Junio C Hamano wrote:
> >> So it is a misconfiguration if you only set GIT_WORK_TREE without
> >> setting GIT_DIR.
> >
> > Hmm. I have frequently done this when my cwd is a git repository (e.g.,
> > a bare one), and it works as you'd expect (find the git-dir in the
> > current path, then the working tree via $GIT_WORK_TREE).
>
> Hmm, does what is done by "git add HEAD" in such a situation match
> what you'd expect?
>
> git init work
> cd work; date >HEAD; git commit -m initial
> git push ../bare master:master
> date >>HEAD
> export GIT_WORK_TREE=$(pwd)
> cd ..
> git --bare init bare
> cd bare
> git add HEAD
I had to tweak your commands a little, but I assume the part you are
interested in is the end, when git-add finds HEAD in $GIT_WORK_TREE and
not the bare repository.
And yes, that is exactly what I'd expect, and why it is useful (if you
wanted to add arbitrary cruft from the bare repo, you'd set
$GIT_WORK_TREE to point there).
> I'd have to say that this invites unnecessary confusion, even though
> I agree that "go to the GIT_WORK_TREE and take pathspecs relative to
> that directory" is the only sensible thing for us to be doing.
>
> But that is not an issue about "set only work-tree" (it is about
> "run from outside the work-tree").
Yeah, there are two things going on:
1. Without $GIT_DIR but with $GIT_WORK_TREE, we find $GIT_DIR via the
usual discovery path.
2. When outside $GIT_WORK_TREE, any work-tree operations work as if
they were started from $GIT_WORK_TREE.
And relying on (1) almost always relies on (2), unless your work-tree
happens to be inside the discovery path for your $GIT_DIR. So you could
do:
git init repo
mkdir repo/subdir
echo content >file
GIT_WORK_TREE=$(pwd) git add .
which adds "file" at the top-level. And we used only rule (1), not rule
(2). I don't know whether people actually do that or not (I guess it
could be useful for tricky subtree things).
-Peff
next prev parent reply other threads:[~2016-03-29 20:26 UTC|newest]
Thread overview: 16+ messages / expand[flat|nested] mbox.gz Atom feed top
2016-03-29 11:42 `git rev-parse --is-inside-work-tree` and $GIT_WORK_TREE Elliott Cable
2016-03-29 11:53 ` Elliott Cable
2016-03-29 12:33 ` John Keeping
2016-03-29 15:08 ` Junio C Hamano
2016-03-29 19:41 ` Jeff King
2016-03-29 19:56 ` Junio C Hamano
2016-03-29 20:26 ` Jeff King [this message]
2016-03-29 20:34 ` Jeff King
2016-03-29 20:52 ` John Keeping
2016-03-29 21:21 ` Jeff King
2016-03-29 22:00 ` John Keeping
2016-03-29 22:14 ` John Keeping
2016-03-29 22:16 ` Jeff King
2016-03-29 22:35 ` Junio C Hamano
2016-03-30 0:53 ` Duy Nguyen
2016-04-01 0:49 ` Elliott Cable
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=20160329202626.GC9527@sigill.intra.peff.net \
--to=peff@peff.net \
--cc=git@vger.kernel.org \
--cc=gitster@pobox.com \
--cc=john@keeping.me.uk \
--cc=me@ell.io \
/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).