git@vger.kernel.org mailing list mirror (one of many)
 help / color / mirror / code / Atom feed
* Inconsistent results from git rev-parse --show-toplevel
@ 2020-01-24 18:07 Crabtree, Andrew
  2020-01-24 19:59 ` Junio C Hamano
  0 siblings, 1 reply; 8+ messages in thread
From: Crabtree, Andrew @ 2020-01-24 18:07 UTC (permalink / raw)
  To: git@vger.kernel.org

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. 
It may also be related to using worktrees.  Haven't had a chance to test thoroughly.

Regards,
-Andrew

Git Version -  2.25.0

pre-commit hook

#!/bin/bash
env
pwd
git rev-parse --show-toplevel
cd subdir
pwd
git-rev-parse --show-toplevel

Create a repo with a subdirectory.   Commit as normal.  Output from the hook looks as expected.  Create a worktree, and commit there and it appears as though it is returning incorrect results after changing directory.

Git repo is in /tmp/revparse_test
Worktree is in /tmp/revparse_test_worktree

Committing in /tmp/revparse_test yields the below, as expected 
/tmp/revparse_test
/tmp/revparse_test
/tmp/revparse_test/subdir
/tmp/revparse_test


Committing in the worktree yields below, with the final line seeming incorrect.
/tmp/revparse_test_worktree
/tmp/revparse_test_worktree
/tmp/revparse_test_worktree/subdir
/tmp/revparse_test_worktree/subdir

^ permalink raw reply	[flat|nested] 8+ messages in thread

end of thread, other threads:[~2020-02-14  6:36 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-01-24 18:07 Inconsistent results from git rev-parse --show-toplevel Crabtree, Andrew
2020-01-24 19:59 ` Junio C Hamano
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

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).