Use a more robust method to look for the Git root.
In particular, checking for a directory named '.git' fails when 'git-worktree'
is used, since worktrees get a file named '.git', not a directory.
Conveniently, Git commands in worktrees behave superficially as if the worktree
is itself a normal Git repository, so we can simply ask Git for the top level
directory and compare it with the provided path.
Change-Id: I41ef4667ae7121b304b03f8c39ec4c700d1f1c4e
diff --git a/tools/git.py b/tools/git.py
index 7c234cd..a133a48 100644
--- a/tools/git.py
+++ b/tools/git.py
@@ -27,9 +27,13 @@
import re
import util
import os.path
+from pipes import quote
def is_git_repository_root(path):
- return os.path.isdir(os.path.join(path, '.git'))
+ command = 'git -C ' + quote(path) + ' rev-parse --show-toplevel'
+ status, toplevel = util.getstatusoutput(command)
+ if status != 0: return False
+ return os.path.samefile(toplevel, path)
def get_tracked_files():
command = 'git ls-tree HEAD -r --full-tree --name-only'