changeset 447:1189e52ba27c

Strip trailing slash for heroku-style URLs. Fixes #31. Includes a regression test for the fix.
author Jason R. Coombs <jaraco@jaraco.com>
date Fri, 27 Jan 2012 22:48:55 -0500
parents 7e6fc0efc500
children e58a6d0b80e2
files hggit/git_handler.py tests/test-url-parsing.py tests/test-url-parsing.py.out
diffstat 3 files changed, 40 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- a/hggit/git_handler.py
+++ b/hggit/git_handler.py
@@ -1110,6 +1110,10 @@
             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
 
--- a/tests/test-url-parsing.py
+++ b/tests/test-url-parsing.py
@@ -40,6 +40,26 @@
         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"
@@ -72,6 +92,8 @@
     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']:
--- a/tests/test-url-parsing.py.out
+++ b/tests/test-url-parsing.py.out
@@ -10,6 +10,20 @@
 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'