Fix UnboundLocalError: local variable 'port' when using SSH
If the SSH URL doesn't contain a port number, but uses the ssh://
or git+ssh:// syntax we raised a Python runtime error due to the
'port' local variable not being assigned a value. Default it to
the IANA assigned port for SSH, 22.
Signed-off-by: Shawn O. Pearce <sop@google.com>
diff --git a/git_config.py b/git_config.py
index 163b080..53b52c8 100644
--- a/git_config.py
+++ b/git_config.py
@@ -337,12 +337,9 @@
_ssh_cache = {}
_ssh_master = True
-def _open_ssh(host, port=None):
+def _open_ssh(host, port):
global _ssh_master
- if port is None:
- port = 22
-
key = '%s:%s' % (host, port)
if key in _ssh_cache:
return True
@@ -397,6 +394,8 @@
host = m.group(2)
if ':' in host:
host, port = host.split(':')
+ else:
+ port = 22
if scheme in ('ssh', 'git+ssh', 'ssh+git'):
return _open_ssh(host, port)
return False
@@ -404,7 +403,7 @@
m = URI_SCP.match(url)
if m:
host = m.group(1)
- return _open_ssh(host)
+ return _open_ssh(host, 22)
class Remote(object):