Keep empty query string in resolved git url

Pagure: #152
Signed-off-by: Lubomír Sedlář <lsedlar@redhat.com>
This commit is contained in:
Lubomír Sedlář 2016-02-16 10:42:59 +01:00
parent 284d3a3510
commit 826afdc162
2 changed files with 14 additions and 1 deletions

View File

@ -243,7 +243,11 @@ def resolve_git_url(url):
raise RuntimeError('Failed to resolve %s', url) raise RuntimeError('Failed to resolve %s', url)
fragment = lines[0].split()[0] 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]} # fomat: {arch|*: [data]}

View File

@ -48,6 +48,15 @@ class TestGitRefResolver(unittest.TestCase):
run.assert_called_once_with(['git', 'ls-remote', 'https://git.example.com/repo.git', 'HEAD']) 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): class TestGetVariantData(unittest.TestCase):
def test_get_simple(self): def test_get_simple(self):