Bug 1277103 - Always use git rev-parse to get git_dir. r?gps
When `git mozreview credentials` is executed by git/cinnabar from a
worktree, GIT_DIR is set to the directory of the private worktree
repository, and GIT_COMMON_DIR is not set, so we don't actually get the
right directory, and the credentials command fails with the error saying
running git mozreview configure is necessary.
So just always rely on git rev-parse.
--- a/git/commands/git-mozreview
+++ b/git/commands/git-mozreview
@@ -53,32 +53,28 @@ CLIENT_CAPABILITIES = {
'bzapikeys',
'jsonproto',
'commitid',
}
MAX_REVIEW_COMMITS = 100
-git_dir = os.environ.get('GIT_COMMON_DIR')
-if not git_dir:
- git_dir = os.environ.get('GIT_DIR')
-if not git_dir:
- git_dir = subprocess.check_output(
- ['git', 'rev-parse', '--no-flags', '--git-common-dir']).rstrip('\n')
- # Up to version 2.8, git rev-parse --git-common-dir returns '.git' when in
- # a subdirectory of the main work tree. In 2.8, it returns 'subdir/.git',
- # which is wrong as well.
- # In both cases, we can just fall through to --git-dir.
- # When running from a separate work tree, --git-common-dir always returns
- # an absolute path. When running from the main work tree and
- # --git-common-dir returns an absolute path, it's correct. So we can assume
- # that when it returns a relative path, we can use --git-dir instead.
- if not os.path.isabs(git_dir):
- git_dir = None
+git_dir = subprocess.check_output(
+ ['git', 'rev-parse', '--no-flags', '--git-common-dir']).rstrip('\n')
+# Up to version 2.8, git rev-parse --git-common-dir returns '.git' when in
+# a subdirectory of the main work tree. In 2.8, it returns 'subdir/.git',
+# which is wrong as well.
+# In both cases, we can just fall through to --git-dir.
+# When running from a separate work tree, --git-common-dir always returns
+# an absolute path. When running from the main work tree and
+# --git-common-dir returns an absolute path, it's correct. So we can assume
+# that when it returns a relative path, we can use --git-dir instead.
+if not os.path.isabs(git_dir):
+ git_dir = None
# git versions before 2.5 don't support --git-common-dir, so fallback to
# --git-dir
if not git_dir:
git_dir = subprocess.check_output(
['git', 'rev-parse', '--git-dir']).rstrip('\n')
def gethgui():