Skip to content
This repository has been archived by the owner on Jul 24, 2020. It is now read-only.

Commit

Permalink
Strip trailing slash for heroku-style URLs. Fixes #31. Includes a reg…
Browse files Browse the repository at this point in the history
…ression test for the fix.
  • Loading branch information
jaraco committed Jan 28, 2012
1 parent fcb147c commit ed4cbf8
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 0 deletions.
4 changes: 4 additions & 0 deletions hggit/git_handler.py
Expand Up @@ -1110,6 +1110,10 @@ def get_transport_and_path(self, uri):
host, port, sepr, path = res['host'], res['port'], res['sepr'], res['path']
if sepr == '/':
path = '/' + path
# strip trailing slash for heroku-style URLs
# ssh+git://git@heroku.com:project.git/
if sepr == ':' and path.endswith('.git/'):
path = path.rstrip('/')
if port:
client.port = port

Expand Down
22 changes: 22 additions & 0 deletions tests/test-url-parsing.py
Expand Up @@ -40,6 +40,26 @@ def test_ssh_heroku_style(self):
client, path = self.handler.get_transport_and_path(url)
self.assertEquals(path, 'webjam.git')
self.assertEquals(client.host, 'git@heroku.com')
# also test that it works even if heroku isn't in the name
url = "git+ssh://git@compatible.com:webjam.git"
client, path = self.handler.get_transport_and_path(url)
self.assertEquals(path, 'webjam.git')
self.assertEquals(client.host, 'git@compatible.com')

def test_ssh_heroku_style_with_trailing_slash(self):
# some versions of mercurial add a trailing slash even if
# the user didn't supply one.
url = "git+ssh://git@heroku.com:webjam.git/"
client, path = self.handler.get_transport_and_path(url)
self.assertEquals(path, 'webjam.git')
self.assertEquals(client.host, 'git@heroku.com')

def test_heroku_style_with_port(self):
url = "git+ssh://git@heroku.com:999:webjam.git"
client, path = self.handler.get_transport_and_path(url)
self.assertEquals(path, 'webjam.git')
self.assertEquals(client.host, 'git@heroku.com')
self.assertEquals(client.port, '999')

def test_gitdaemon_style(self):
url = "git://github.com/webjam/webjam.git"
Expand Down Expand Up @@ -72,6 +92,8 @@ def test_gitdaemon_style_with_port(self):
for test in ['test_ssh_github_style_slash',
'test_ssh_github_style_colon',
'test_ssh_heroku_style',
'test_ssh_heroku_style_with_trailing_slash',
'test_heroku_style_with_port',
'test_gitdaemon_style',
'test_ssh_github_style_slash_with_port',
'test_gitdaemon_style_with_port']:
Expand Down
14 changes: 14 additions & 0 deletions tests/test-url-parsing.py.out
Expand Up @@ -10,6 +10,20 @@ git@github.com
webjam.git
% expect 'git@heroku.com'
git@heroku.com
% expect 'webjam.git'
webjam.git
% expect 'git@compatible.com'
git@compatible.com
% expect 'webjam.git'
webjam.git
% expect 'git@heroku.com'
git@heroku.com
% expect 'webjam.git'
webjam.git
% expect 'git@heroku.com'
git@heroku.com
% expect '999'
999
% expect '/webjam/webjam.git'
/webjam/webjam.git
% expect 'github.com'
Expand Down

0 comments on commit ed4cbf8

Please sign in to comment.