@ -85,6 +85,16 @@ def p4_build_cmd(cmd):
real_cmd += cmd
real_cmd += cmd
return real_cmd
return real_cmd
def git_dir(path):
""" Return TRUE if the given path is a git directory (/path/to/dir/.git).
This won't automatically add ".git" to a directory.
"""
d = read_pipe(["git", "--git-dir", path, "rev-parse", "--git-dir"], True).strip()
if not d or len(d) == 0:
return None
else:
return d
def chdir(path, is_client_path=False):
def chdir(path, is_client_path=False):
"""Do chdir to the given path, and set the PWD environment
"""Do chdir to the given path, and set the PWD environment
variable for use by P4. It does not look at getcwd() output.
variable for use by P4. It does not look at getcwd() output.
@ -563,10 +573,7 @@ def currentGitBranch():
return read_pipe(["git", "name-rev", "HEAD"]).split(" ")[1].strip()
return read_pipe(["git", "name-rev", "HEAD"]).split(" ")[1].strip()
def isValidGitDir(path):
def isValidGitDir(path):
if (os.path.exists(path + "/HEAD")
return git_dir(path) != None
and os.path.exists(path + "/refs") and os.path.exists(path + "/objects")):
return True;
return False
def parseRevision(ref):
def parseRevision(ref):
return read_pipe("git rev-parse %s" % ref).strip()
return read_pipe("git rev-parse %s" % ref).strip()
@ -3682,6 +3689,7 @@ def main():
if cmd.gitdir == None:
if cmd.gitdir == None:
cmd.gitdir = os.path.abspath(".git")
cmd.gitdir = os.path.abspath(".git")
if not isValidGitDir(cmd.gitdir):
if not isValidGitDir(cmd.gitdir):
# "rev-parse --git-dir" without arguments will try $PWD/.git
cmd.gitdir = read_pipe("git rev-parse --git-dir").strip()
cmd.gitdir = read_pipe("git rev-parse --git-dir").strip()
if os.path.exists(cmd.gitdir):
if os.path.exists(cmd.gitdir):
cdup = read_pipe("git rev-parse --show-cdup").strip()
cdup = read_pipe("git rev-parse --show-cdup").strip()
@ -3694,6 +3702,7 @@ def main():
else:
else:
die("fatal: cannot locate git repository at %s" % cmd.gitdir)
die("fatal: cannot locate git repository at %s" % cmd.gitdir)
# so git commands invoked from the P4 workspace will succeed
os.environ["GIT_DIR"] = cmd.gitdir
os.environ["GIT_DIR"] = cmd.gitdir
if not cmd.run(args):
if not cmd.run(args):