util: Resolve HEAD in repos that have a remote
JIRA: COMPOSE-3597 Signed-off-by: Lubomír Sedlář <lsedlar@redhat.com>
This commit is contained in:
parent
d01084337e
commit
f1263eeacb
@ -265,7 +265,10 @@ def resolve_git_ref(repourl, ref):
|
||||
|
||||
lines = []
|
||||
for line in output.split("\n"):
|
||||
if line and ("refs/heads/" in line or "refs/tags/" in line or "HEAD" in line):
|
||||
# Keep only lines that represent branches and tags, and also a line for
|
||||
# currently checked out HEAD. The leading tab is required to
|
||||
# distinguish it from HEADs that could exist in remotes.
|
||||
if line and ("refs/heads/" in line or "refs/tags/" in line or "\tHEAD" in line):
|
||||
lines.append(line)
|
||||
if len(lines) == 0:
|
||||
# Branch does not exist in remote repo
|
||||
|
@ -61,6 +61,20 @@ class TestGitRefResolver(unittest.TestCase):
|
||||
universal_newlines=True,
|
||||
)
|
||||
|
||||
@mock.patch('pungi.util.run')
|
||||
def test_resolve_ref_with_remote_head(self, run):
|
||||
run.return_value = (
|
||||
0, "CAFEBABE\tHEAD\nBABECAFE\trefs/remotes/origin/HEAD"
|
||||
)
|
||||
|
||||
ref = util.resolve_git_ref("https://git.example.com/repo.git", "HEAD")
|
||||
|
||||
self.assertEqual(ref, "CAFEBABE")
|
||||
run.assert_called_once_with(
|
||||
["git", "ls-remote", "https://git.example.com/repo.git", "HEAD"],
|
||||
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')
|
||||
|
Loading…
Reference in New Issue
Block a user