Bug 1277103 - Always use git rev-parse to get git_dir. r?gps draft
authorMike Hommey <mh@glandium.org>
Wed, 01 Jun 2016 08:19:28 +0900
changeset 8254 1acfe85ee24927d44d509f2c8dd3f9d19a3cd57c
parent 8253 a52ee24d3d53fb334ae83da35ba8996bb3f1f43b
push id885
push userbmo:mh+mozilla@glandium.org
push dateTue, 31 May 2016 23:27:25 +0000
reviewersgps
bugs1277103
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.
git/commands/git-mozreview
--- 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():