From d3900296af9428d792b3700d66187bd37f3d498e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lubom=C3=ADr=20Sedl=C3=A1=C5=99?= Date: Mon, 16 May 2016 07:51:13 +0200 Subject: [PATCH] [util] Resolve git+https URLs MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Lubomír Sedlář --- pungi/util.py | 6 +++++- tests/test_util.py | 9 +++++++++ 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/pungi/util.py b/pungi/util.py index 7498ed7c..0522eeb1 100644 --- a/pungi/util.py +++ b/pungi/util.py @@ -243,7 +243,11 @@ def resolve_git_url(url): if not ref: return url - baseurl = urlparse.urlunsplit((r.scheme, r.netloc, r.path, '', '')) + # Remove git+ prefix from scheme if present. This is for resolving only, + # the final result must use original scheme. + scheme = r.scheme.replace('git+', '') + + baseurl = urlparse.urlunsplit((scheme, r.netloc, r.path, '', '')) _, output = run(['git', 'ls-remote', baseurl, ref]) lines = [line for line in output.split('\n') if line] diff --git a/tests/test_util.py b/tests/test_util.py index 97892b71..af28cdc5 100755 --- a/tests/test_util.py +++ b/tests/test_util.py @@ -68,6 +68,15 @@ class TestGitRefResolver(unittest.TestCase): run.assert_called_once_with(['git', 'ls-remote', 'https://git.example.com/repo.git', 'HEAD']) self.assertEqual(url, 'https://git.example.com/repo.git?#CAFEBABE') + @mock.patch('pungi.util.run') + def test_resolve_strip_git_plus_prefix(self, run): + run.return_value = (0, 'CAFEBABE\tHEAD\n') + + url = util.resolve_git_url('git+https://git.example.com/repo.git#HEAD') + + run.assert_called_once_with(['git', 'ls-remote', 'https://git.example.com/repo.git', 'HEAD']) + self.assertEqual(url, 'git+https://git.example.com/repo.git#CAFEBABE') + class TestGetVariantData(unittest.TestCase): def test_get_simple(self):