git: Properly handle gitfiles
For additional worktrees, .git is not a directory, but instead a "gitfile"
pointing to the actual .git directory.
To properly handle those, leverage git-rev-parse for validating git
repositories instead of determining it by checking whether there is
a .git directory.
Test: git worktree add worktree; cd worktree; git branch --set-upstream-to=goog/pi-dev; ../pre-upload.py --dir .
Bug: 77999387
Change-Id: I18b2fd6df58e24e644cd3c29eed99a80ae462fb0
diff --git a/pre-upload.py b/pre-upload.py
index 80473c1..fffc03c 100755
--- a/pre-upload.py
+++ b/pre-upload.py
@@ -394,8 +394,8 @@
opts.dir = os.path.dirname(os.path.abspath(git_dir))
elif not os.path.isdir(opts.dir):
parser.error('Invalid dir: %s' % opts.dir)
- elif not os.path.isdir(os.path.join(opts.dir, '.git')):
- parser.error('Not a git directory: %s' % opts.dir)
+ elif not rh.git.is_git_repository(opts.dir):
+ parser.error('Not a git repository: %s' % opts.dir)
# Identify the project if it wasn't specified; this _requires_ the repo
# tool to be installed and for the project to be part of a repo checkout.