git@vger.kernel.org mailing list mirror (one of many)
 help / color / mirror / code / Atom feed
From: "Crabtree, Andrew" <andrew.crabtree@hpe.com>
To: "git@vger.kernel.org" <git@vger.kernel.org>
Subject: Inconsistent results from git rev-parse --show-toplevel
Date: Fri, 24 Jan 2020 18:07:55 +0000	[thread overview]
Message-ID: <TU4PR8401MB111758B9513DD7D8B96CBFAAF90E0@TU4PR8401MB1117.NAMPRD84.PROD.OUTLOOK.COM> (raw)

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

             reply	other threads:[~2020-01-24 18:07 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-01-24 18:07 Crabtree, Andrew [this message]
2020-01-24 19:59 ` Inconsistent results from git rev-parse --show-toplevel 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

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

  List information: http://vger.kernel.org/majordomo-info.html

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=TU4PR8401MB111758B9513DD7D8B96CBFAAF90E0@TU4PR8401MB1117.NAMPRD84.PROD.OUTLOOK.COM \
    --to=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.
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).