handle git ref names with slashes in them
authorIan Clatworthy <ian.clatworthy@canonical.com>
Thu, 22 Oct 2009 07:55:22 +0000 (17:55 +1000)
committerIan Clatworthy <ian.clatworthy@canonical.com>
Thu, 22 Oct 2009 07:55:22 +0000 (17:55 +1000)
branch_mapper.py
tests/test_branch_mapper.py

index f6d06707aca6e419c1b7d5f8bc9a3045d92b1c60..3bfc39b2519fdb1cf7e6563778c1fc12ce650d36 100644 (file)
@@ -32,11 +32,15 @@ class BranchMapper(object):
                 parts.pop(0)
             category = parts.pop(0)
             if category == 'heads':
-                bazaar_name = self._git_to_bzr_name(parts[-1])
+                git_name = '/'.join(parts)
+                bazaar_name = self._git_to_bzr_name(git_name)
             else:
+                if category == 'remotes' and parts[0] == 'origin':
+                    parts.pop(0)
+                git_name = '/'.join(parts)
                 if category.endswith('s'):
                     category = category[:-1]
-                name_no_ext = self._git_to_bzr_name(parts[-1])
+                name_no_ext = self._git_to_bzr_name(git_name)
                 bazaar_name = "%s.%s" % (name_no_ext, category)
             bazaar_names[ref_name] = bazaar_name
         return bazaar_names
index fe1b53341c19880d4f85d9c2c76250e04a083025..0a50eec2f80ec41f945d72fb3d65168050a6329e 100644 (file)
@@ -45,6 +45,26 @@ class TestBranchMapper(tests.TestCase):
             'refs/remotes/origin/foo':          'foo.remote',
             })
 
+    def test_git_to_bzr_with_slashes(self):
+        m = branch_mapper.BranchMapper()
+        git_refs = [
+            'refs/heads/master/slave',
+            'refs/heads/foo/bar',
+            'refs/tags/master/slave',
+            'refs/tags/foo/bar',
+            'refs/remotes/origin/master/slave',
+            'refs/remotes/origin/foo/bar',
+            ]
+        git_to_bzr_map = m.git_to_bzr(git_refs)
+        self.assertEqual(git_to_bzr_map, {
+            'refs/heads/master/slave':              'master/slave',
+            'refs/heads/foo/bar':                   'foo/bar',
+            'refs/tags/master/slave':               'master/slave.tag',
+            'refs/tags/foo/bar':                    'foo/bar.tag',
+            'refs/remotes/origin/master/slave':     'master/slave.remote',
+            'refs/remotes/origin/foo/bar':          'foo/bar.remote',
+            })
+
     def test_git_to_bzr_for_trunk(self):
         # As 'master' in git is mapped to trunk in bzr, we need to handle
         # 'trunk' in git in a sensible way.