From 826afdc16219fe2a73828d21396c6cc47b9ff5bd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lubom=C3=ADr=20Sedl=C3=A1=C5=99?= Date: Tue, 16 Feb 2016 10:42:59 +0100 Subject: [PATCH] Keep empty query string in resolved git url MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Pagure: #152 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 d3aa3e57..6aabdaad 100644 --- a/pungi/util.py +++ b/pungi/util.py @@ -243,7 +243,11 @@ def resolve_git_url(url): raise RuntimeError('Failed to resolve %s', url) fragment = lines[0].split()[0] - return urlparse.urlunsplit((r.scheme, r.netloc, r.path, r.query, fragment)) + result = urlparse.urlunsplit((r.scheme, r.netloc, r.path, r.query, fragment)) + if '?#' in url: + # The urlparse library drops empty query string. This hack puts it back in. + result = result.replace('#', '?#') + return result # fomat: {arch|*: [data]} diff --git a/tests/test_util.py b/tests/test_util.py index e2cc0871..9f5d5232 100755 --- a/tests/test_util.py +++ b/tests/test_util.py @@ -48,6 +48,15 @@ class TestGitRefResolver(unittest.TestCase): run.assert_called_once_with(['git', 'ls-remote', 'https://git.example.com/repo.git', 'HEAD']) + @mock.patch('pungi.util.run') + def test_resolve_keep_empty_query_string(self, run): + run.return_value = (0, 'CAFEBABE\tHEAD\n') + + url = util.resolve_git_url('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, 'https://git.example.com/repo.git?#CAFEBABE') + class TestGetVariantData(unittest.TestCase): def test_get_simple(self):