diff options
author | Jacob Bramley <jacob.bramley@arm.com> | 2018-08-15 11:07:51 +0100 |
---|---|---|
committer | Jacob Bramley <jacob.bramley@arm.com> | 2018-08-16 10:38:54 +0000 |
commit | e52f29dd43086d56b20adea36b91317c5a5ff9b5 (patch) | |
tree | d83e7c66522e2ae09097f1144a8b819e0694d605 /tools | |
parent | 44096c4d51e1f2537d35fd2504e82d525ec70099 (diff) |
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
Diffstat (limited to 'tools')
-rw-r--r-- | tools/git.py | 6 |
1 files changed, 5 insertions, 1 deletions
diff --git a/tools/git.py b/tools/git.py index 7c234cdb..a133a48c 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' |