66 lines
2.3 KiB
Diff
66 lines
2.3 KiB
Diff
|
From b0f0579a9e8d31d616ef29e5118ab9bbec392baf Mon Sep 17 00:00:00 2001
|
||
|
From: Lubomír Sedlář <lsedlar@redhat.com>
|
||
|
Date: May 07 2019 11:44:57 +0000
|
||
|
Subject: util: Resolve ref if duplicate branches are present
|
||
|
|
||
|
|
||
|
If the repo contains the same name under multiple directories, make the
|
||
|
resolving work by filtering only to refs/heads and refs/tags.
|
||
|
|
||
|
Fixes: https://pagure.io/pungi/issue/1180
|
||
|
Signed-off-by: Lubomír Sedlář <lsedlar@redhat.com>
|
||
|
|
||
|
---
|
||
|
|
||
|
diff --git a/pungi/util.py b/pungi/util.py
|
||
|
index 86f35d8..d5a9eed 100644
|
||
|
--- a/pungi/util.py
|
||
|
+++ b/pungi/util.py
|
||
|
@@ -263,7 +263,10 @@ def resolve_git_ref(repourl, ref):
|
||
|
|
||
|
_, output = git_ls_remote(repourl, ref)
|
||
|
|
||
|
- lines = [line for line in output.split('\n') if line]
|
||
|
+ lines = []
|
||
|
+ for line in output.split("\n"):
|
||
|
+ if line and ("refs/heads/" in line or "refs/tags/" in line or "HEAD" in line):
|
||
|
+ lines.append(line)
|
||
|
if len(lines) == 0:
|
||
|
# Branch does not exist in remote repo
|
||
|
raise GitUrlResolveError(
|
||
|
@@ -272,7 +275,7 @@ def resolve_git_ref(repourl, ref):
|
||
|
if len(lines) != 1:
|
||
|
# This should never happen. HEAD can not match multiple commits in a
|
||
|
# single repo, and there can not be a repo without a HEAD.
|
||
|
- raise GitUrlResolveError("Failed to resolve %s", repourl)
|
||
|
+ raise GitUrlResolveError("Failed to resolve %r in %s" % (ref, repourl))
|
||
|
|
||
|
return lines[0].split()[0]
|
||
|
|
||
|
diff --git a/tests/test_util.py b/tests/test_util.py
|
||
|
index 5a65df2..820d1cc 100644
|
||
|
--- a/tests/test_util.py
|
||
|
+++ b/tests/test_util.py
|
||
|
@@ -48,6 +48,20 @@ class TestGitRefResolver(unittest.TestCase):
|
||
|
self.assertEqual(ref, "a" * 40)
|
||
|
|
||
|
@mock.patch('pungi.util.run')
|
||
|
+ def test_resolve_ref_multiple_matches(self, run):
|
||
|
+ run.return_value = (
|
||
|
+ 0, "CAFEBABE\trefs/heads/master\nBABECAFE\trefs/remotes/origin/master"
|
||
|
+ )
|
||
|
+
|
||
|
+ ref = util.resolve_git_ref("https://git.example.com/repo.git", "master")
|
||
|
+
|
||
|
+ self.assertEqual(ref, "CAFEBABE")
|
||
|
+ run.assert_called_once_with(
|
||
|
+ ["git", "ls-remote", "https://git.example.com/repo.git", "master"],
|
||
|
+ universal_newlines=True,
|
||
|
+ )
|
||
|
+
|
||
|
+ @mock.patch('pungi.util.run')
|
||
|
def test_resolve_missing_spec(self, run):
|
||
|
url = util.resolve_git_url('https://git.example.com/repo.git')
|
||
|
|
||
|
|