util: Report better error on resolving non-existing branch
When the config contains a git url pointing to a non-existing branch, pungi will fail to get commit hash from that branch and die with a confusing error message. Fixes: #583 Signed-off-by: Lubomír Sedlář <lsedlar@redhat.com>
This commit is contained in:
parent
2bc719a33a
commit
610c4ec596
@ -257,6 +257,10 @@ def resolve_git_url(url):
|
|||||||
_, output = run(['git', 'ls-remote', baseurl, ref])
|
_, output = run(['git', 'ls-remote', baseurl, ref])
|
||||||
|
|
||||||
lines = [line for line in output.split('\n') if line]
|
lines = [line for line in output.split('\n') if line]
|
||||||
|
if len(lines) == 0:
|
||||||
|
# Branch does not exist in remote repo
|
||||||
|
raise RuntimeError('Failed to resolve %s: ref does not exist in remote repo'
|
||||||
|
% url)
|
||||||
if len(lines) != 1:
|
if len(lines) != 1:
|
||||||
# This should never happen. HEAD can not match multiple commits in a
|
# This should never happen. HEAD can not match multiple commits in a
|
||||||
# single repo, and there can not be a repo without a HEAD.
|
# single repo, and there can not be a repo without a HEAD.
|
||||||
|
@ -81,6 +81,17 @@ 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'])
|
||||||
self.assertEqual(url, 'git+https://git.example.com/repo.git#CAFEBABE')
|
self.assertEqual(url, 'git+https://git.example.com/repo.git#CAFEBABE')
|
||||||
|
|
||||||
|
@mock.patch('pungi.util.run')
|
||||||
|
def test_resolve_no_branch_in_remote(self, run):
|
||||||
|
run.return_value = (0, '')
|
||||||
|
|
||||||
|
with self.assertRaises(RuntimeError) as ctx:
|
||||||
|
util.resolve_git_url('https://git.example.com/repo.git?somedir#origin/my-branch')
|
||||||
|
|
||||||
|
run.assert_called_once_with(
|
||||||
|
['git', 'ls-remote', 'https://git.example.com/repo.git', 'refs/heads/my-branch'])
|
||||||
|
self.assertIn('ref does not exist in remote repo', str(ctx.exception))
|
||||||
|
|
||||||
|
|
||||||
class TestGetVariantData(unittest.TestCase):
|
class TestGetVariantData(unittest.TestCase):
|
||||||
def test_get_simple(self):
|
def test_get_simple(self):
|
||||||
|
Loading…
Reference in New Issue
Block a user