@@ -90,6 +90,16 @@ def p4_build_cmd(cmd):
9090 real_cmd += cmd
9191 return real_cmd
9292
93+ def git_dir (path ):
94+ """ Return TRUE if the given path is a git directory (/path/to/dir/.git).
95+ This won't automatically add ".git" to a directory.
96+ """
97+ d = read_pipe (["git" , "--git-dir" , path , "rev-parse" , "--git-dir" ], True ).strip ()
98+ if not d or len (d ) == 0 :
99+ return None
100+ else :
101+ return d
102+
93103def chdir (path , is_client_path = False ):
94104 """Do chdir to the given path, and set the PWD environment
95105 variable for use by P4. It does not look at getcwd() output.
@@ -572,10 +582,7 @@ def currentGitBranch():
572582 return read_pipe (["git" , "name-rev" , "HEAD" ]).split (" " )[1 ].strip ()
573583
574584def isValidGitDir (path ):
575- if (os .path .exists (path + "/HEAD" )
576- and os .path .exists (path + "/refs" ) and os .path .exists (path + "/objects" )):
577- return True ;
578- return False
585+ return git_dir (path ) != None
579586
580587def parseRevision (ref ):
581588 return read_pipe ("git rev-parse %s" % ref ).strip ()
@@ -3725,6 +3732,7 @@ def main():
37253732 if cmd .gitdir == None :
37263733 cmd .gitdir = os .path .abspath (".git" )
37273734 if not isValidGitDir (cmd .gitdir ):
3735+ # "rev-parse --git-dir" without arguments will try $PWD/.git
37283736 cmd .gitdir = read_pipe ("git rev-parse --git-dir" ).strip ()
37293737 if os .path .exists (cmd .gitdir ):
37303738 cdup = read_pipe ("git rev-parse --show-cdup" ).strip ()
@@ -3737,6 +3745,7 @@ def main():
37373745 else :
37383746 die ("fatal: cannot locate git repository at %s" % cmd .gitdir )
37393747
3748+ # so git commands invoked from the P4 workspace will succeed
37403749 os .environ ["GIT_DIR" ] = cmd .gitdir
37413750
37423751 if not cmd .run (args ):
0 commit comments