git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Junio C Hamano <gitster@pobox.com>
To: "Crabtree\, Andrew" <andrew.crabtree@hpe.com>
Cc: "git\@vger.kernel.org" <git@vger.kernel.org>
Subject: Re: Inconsistent results from git rev-parse --show-toplevel
Date: Fri, 24 Jan 2020 11:59:07 -0800	[thread overview]
Message-ID: <xmqqftg4zkvo.fsf@gitster-ct.c.googlers.com> (raw)
In-Reply-To: <TU4PR8401MB111758B9513DD7D8B96CBFAAF90E0@TU4PR8401MB1117.NAMPRD84.PROD.OUTLOOK.COM> (Andrew Crabtree's message of "Fri, 24 Jan 2020 18:07:55 +0000")

"Crabtree, Andrew" <andrew.crabtree@hpe.com> writes:

> I ran into an issue where 'git rev-parse --show-toplevel' is reporting the current directory instead of the root of the repository.
> In my case I'm running it from within the pre-commit hook, and it seems like it might be related to GIT_DIR being set. 

Running "git" with GIT_DIR exported (or "git --git-dir=<dir>") tells
Git that it should not perform the usual "does this directory has a
subdirectory .git that is a repository?  If not, go one level up and
repeat the check" repository discovery.  Because the repository
discovery serves the purpose of finding both the repository and the
top of the working tree, disabling the discovery means you either
need to tell Git where the top of the working tree is, or you are
already at the top of the working tree by chdir()'ing to it.

Because you do not know where the top level is (otherwise you would
not be asking "rev-parse --show-toplevel" about it), either is
an option for you, but you can "unset GIT_DIR" to stop telling Git
that it should not perform the repository discovery.

  reply	other threads:[~2020-01-24 19:59 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-01-24 18:07 Inconsistent results from git rev-parse --show-toplevel Crabtree, Andrew
2020-01-24 19:59 ` Junio C Hamano [this message]
2020-01-25 19:31   ` Crabtree, Andrew
2020-01-25 19:53     ` Jeff King
2020-01-25 22:22       ` Crabtree, Andrew
2020-01-30 10:29         ` Jeff King
2020-01-30 21:59           ` Crabtree, Andrew
2020-02-14  6:36             ` Jeff King

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=xmqqftg4zkvo.fsf@gitster-ct.c.googlers.com \
    --to=gitster@pobox.com \
    --cc=andrew.crabtree@hpe.com \
    --cc=git@vger.kernel.org \
    /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).