From 384dfbbbb2dafd3430050dc47aecfaa42016919a Mon Sep 17 00:00:00 2001 From: Travis Willard Date: Mon, 3 Apr 2017 15:43:37 -0400 Subject: [PATCH 1/3] Support ssh:// URLs from github if they don't have the ssh:// scheme explicit in the URL --- passport/case.py | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/passport/case.py b/passport/case.py index e7f779e..0270c19 100644 --- a/passport/case.py +++ b/passport/case.py @@ -76,7 +76,16 @@ def gen_candidates(ids, url): yield (key, value) local_passports = config["git_passports"] - netloc = urllib.parse.urlparse(url)[1] + + # For a lot of SSH git clones the scheme is implicit in the URLs provided to + # copy-paste from the website (ie. git@github.com:project/name.git) - + # without the explicit ssh:// on the front urllib doesn't play nice with + # the URL + parsedurl = urllib.parse.urlparse(url) + if parsedurl.hostname == None: + parsedurl = urllib.parse.urlparse("ssh://" + url) + + netloc = parsedurl.hostname candidates = dict(gen_candidates(local_passports, netloc)) From 373aab4bef886dfd5a60969d2849924c3b235bbf Mon Sep 17 00:00:00 2001 From: Travis Willard Date: Mon, 3 Apr 2017 15:44:05 -0400 Subject: [PATCH 2/3] Wait for each successive git config command to finish before calling the next to avoid race conditions on the locked .git/config file --- passport/git.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/passport/git.py b/passport/git.py index 9a1a4b3..1206620 100644 --- a/passport/git.py +++ b/passport/git.py @@ -86,13 +86,14 @@ def config_set(config, value, property): Exception: If subprocess.Popen() fails """ try: - subprocess.Popen([ + config = subprocess.Popen([ "git", "config", "--local", "user." + property, value ], stdout=subprocess.PIPE) + config.wait() except Exception: raise From e6f4a4af7e63e94be0725d15934480f6f217cccf Mon Sep 17 00:00:00 2001 From: Travis Willard Date: Mon, 3 Apr 2017 15:51:13 -0400 Subject: [PATCH 3/3] Rework race-condition fix to match existing style of file --- passport/git.py | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/passport/git.py b/passport/git.py index 1206620..5c482ff 100644 --- a/passport/git.py +++ b/passport/git.py @@ -86,20 +86,25 @@ def config_set(config, value, property): Exception: If subprocess.Popen() fails """ try: - config = subprocess.Popen([ + git_process = subprocess.Popen([ "git", "config", "--local", "user." + property, value ], stdout=subprocess.PIPE) - config.wait() - except Exception: - raise + # Captures the git return code + exit_status = git_process.wait() - return True + if exit_status == 0: + return True + else: + return False + + except Exception: + raise def config_remove(verbose=True): """ Remove an existing Git identity.