From: Ben Keene <seraphire@xxxxxxxxx> When a computer is configured to use Git for windows and Python for windows, and not a Unix subsystem like cygwin or WSL, the directory separator changes and causes git-p4 to fail to properly determine paths. Fix 3 path separator errors: 1. getUserCacheFilename should not use string concatenation. Change this code to use os.path.join to build an OS tolerant path. 2. defaultDestiantion used the OS.path.split to split depot paths. This is incorrect on windows. Change the code to split on a forward slash(/) instead since depot paths use this character regardless of the operating system. 3. The call to isvalidGitDir() in the main code also used a literal forward slash. Change the cose to use os.path.join to correctly format the path for the operating system. These three changes allow the suggested windows configuration to properly locate files while retaining the existing behavior on non-windows operating systems. Signed-off-by: Ben Keene <seraphire@xxxxxxxxx> (cherry picked from commit a5b45c12c3861638a933b05a1ffee0c83978dcb2) --- git-p4.py | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/git-p4.py b/git-p4.py index 2659531c2e..7ac8cb42ef 100755 --- a/git-p4.py +++ b/git-p4.py @@ -1454,8 +1454,10 @@ def p4UserIsMe(self, p4User): return True def getUserCacheFilename(self): + """ Returns the filename of the username cache + """ home = os.environ.get("HOME", os.environ.get("USERPROFILE")) - return home + "/.gitp4-usercache.txt" + return os.path.join(home, ".gitp4-usercache.txt") def getUserMapFromPerforceServer(self): if self.userMapFromPerforceServer: @@ -3973,13 +3975,16 @@ def __init__(self): self.cloneBare = False def defaultDestination(self, args): + """ Returns the last path component as the default git + repository directory name + """ ## TODO: use common prefix of args? depotPath = args[0] depotDir = re.sub("(@[^@]*)$", "", depotPath) depotDir = re.sub("(#[^#]*)$", "", depotDir) depotDir = re.sub(r"\.\.\.$", "", depotDir) depotDir = re.sub(r"/$", "", depotDir) - return os.path.split(depotDir)[1] + return depotDir.split('/')[-1] def run(self, args): if len(args) < 1: @@ -4252,8 +4257,8 @@ def main(): chdir(cdup); if not isValidGitDir(cmd.gitdir): - if isValidGitDir(cmd.gitdir + "/.git"): - cmd.gitdir += "/.git" + if isValidGitDir(os.path.join(cmd.gitdir, ".git")): + cmd.gitdir = os.path.join(cmd.gitdir, ".git") else: die("fatal: cannot locate git repository at %s" % cmd.gitdir) -- gitgitgadget