Thread (7 messages) flat view 7 messages, 3 authors, 2020-02-14

Re: Inconsistent results from git rev-parse --show-toplevel

From: Junio C Hamano <hidden>
Date: 2020-01-24 19:59:12

Possibly related (same subject, not in this thread)

"Crabtree, Andrew" [off-list ref] 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.
Keyboard shortcuts
hback out one level
jnext message in thread
kprevious message in thread
ldrill in
Escclose help / fold thread tree
?toggle this help