Skip to content

Commit

Permalink
Fix handling of unknown URL schemes in get_transport_and_path. (jelme…
Browse files Browse the repository at this point in the history
  • Loading branch information
jelmer committed Nov 20, 2016
1 parent 3375562 commit d75a1de
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 4 deletions.
3 changes: 3 additions & 0 deletions NEWS
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,9 @@
consistent with the documentation for that method.
(#461, Jelmer Vernooij)

* Fix handling of unknown URL schemes in get_transport_and_path.
(#465, Jelmer Vernooij)

0.15.0 2016-10-09

BUG FIXES
Expand Down
12 changes: 8 additions & 4 deletions dulwich/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -1273,12 +1273,16 @@ def get_transport_and_path(location, **kwargs):

if ':' in location and not '@' in location:
# SSH with no user@, zero or one leading slash.
(hostname, path) = location.split(':')
(hostname, path) = location.split(':', 1)
return SSHGitClient(hostname, **kwargs), path
elif '@' in location and ':' in location:
elif ':' in location:
# SSH with user@host:foo.
user_host, path = location.split(':')
user, host = user_host.rsplit('@')
user_host, path = location.split(':', 1)
if '@' in user_host:
user, host = user_host.rsplit('@', 1)
else:
user = None
host = user_host
return SSHGitClient(host, username=user, **kwargs), path

# Otherwise, assume it's a local path.
Expand Down
16 changes: 16 additions & 0 deletions dulwich/tests/test_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -380,6 +380,22 @@ def test_ssh_port_explicit(self):
self.assertEqual(1234, c.port)
self.assertEqual('bar/baz', path)

def test_username_and_port_explicit_unknown_scheme(self):
c, path = get_transport_and_path(
'unknown://git@server:7999/dply/stuff.git')
self.assertTrue(isinstance(c, SSHGitClient))
self.assertEqual('unknown', c.host)
self.assertEqual('//git@server:7999/dply/stuff.git', path)

def test_username_and_port_explicit(self):
c, path = get_transport_and_path(
'ssh://git@server:7999/dply/stuff.git')
self.assertTrue(isinstance(c, SSHGitClient))
self.assertEqual('git', c.username)
self.assertEqual('server', c.host)
self.assertEqual(7999, c.port)
self.assertEqual('dply/stuff.git', path)

def test_ssh_abspath_explicit(self):
c, path = get_transport_and_path('git+ssh://foo.com//bar/baz')
self.assertTrue(isinstance(c, SSHGitClient))
Expand Down

0 comments on commit d75a1de

Please sign in to comment.