Bug 1274174 - Work around git 2.8 bug in its output for rev-parse --git-common-dir. r=gps
--- a/git/commands/git-mozreview
+++ b/git/commands/git-mozreview
@@ -60,22 +60,24 @@ 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 a non worktree.
- # In this case, we can just fall through to --git-dir.
- # git rev-parse --show-cdup will return an empty string if we are at the
- # top-level, and '../' * depth otherwise.
- if git_dir == '.git' and subprocess.check_output(
- ['git', 'rev-parse', '--show-cdup']).strip():
+ # 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')