diff options
author | Junio C Hamano <gitster@pobox.com> | 2016-12-19 14:45:37 -0800 |
---|---|---|
committer | Junio C Hamano <gitster@pobox.com> | 2016-12-19 14:45:37 -0800 |
commit | 101f3dc92a4cedb1f359f6ddce913b631ffa75b6 (patch) | |
tree | 4a2a080defff5758fff445e3d31901138be81968 /git-p4.py | |
parent | 09b4fdb5f396612dd50236ae5395a74600d2ab84 (diff) | |
parent | 378f7be1e74661ff1480cc44a5f039ef85da7288 (diff) | |
download | git-101f3dc92a4cedb1f359f6ddce913b631ffa75b6.tar.gz |
Merge branch 'ld/p4-worktree'
"git p4" didn't interact with the internal of .git directory
correctly in the modern "git-worktree"-enabled world.
* ld/p4-worktree:
git-p4: support git worktrees
Diffstat (limited to 'git-p4.py')
-rwxr-xr-x | git-p4.py | 17 |
1 files changed, 13 insertions, 4 deletions
@@ -90,6 +90,16 @@ def p4_build_cmd(cmd): real_cmd += 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): """Do chdir to the given path, and set the PWD environment variable for use by P4. It does not look at getcwd() output. @@ -572,10 +582,7 @@ def currentGitBranch(): return read_pipe(["git", "name-rev", "HEAD"]).split(" ")[1].strip() def isValidGitDir(path): - if (os.path.exists(path + "/HEAD") - and os.path.exists(path + "/refs") and os.path.exists(path + "/objects")): - return True; - return False + return git_dir(path) != None def parseRevision(ref): return read_pipe("git rev-parse %s" % ref).strip() @@ -3725,6 +3732,7 @@ def main(): if cmd.gitdir == None: cmd.gitdir = os.path.abspath(".git") 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() if os.path.exists(cmd.gitdir): cdup = read_pipe("git rev-parse --show-cdup").strip() @@ -3737,6 +3745,7 @@ def main(): else: 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 if not cmd.run(args): |