From e51dfab051be112a9f4c85006b1916a07e3062a2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lubom=C3=ADr=20Sedl=C3=A1=C5=99?= Date: Tue, 7 May 2019 14:43:16 +0200 Subject: [PATCH] Backport fixes for cloning git repositories --- 1183.patch | 65 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1184.patch | 32 +++++++++++++++++++++++++++ pungi.spec | 7 +++++- 3 files changed, 103 insertions(+), 1 deletion(-) create mode 100644 1183.patch create mode 100644 1184.patch diff --git a/1183.patch b/1183.patch new file mode 100644 index 00000000..9257f07d --- /dev/null +++ b/1183.patch @@ -0,0 +1,65 @@ +From b0f0579a9e8d31d616ef29e5118ab9bbec392baf Mon Sep 17 00:00:00 2001 +From: Lubomír Sedlář +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ář + +--- + +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') + + diff --git a/1184.patch b/1184.patch new file mode 100644 index 00000000..9908583a --- /dev/null +++ b/1184.patch @@ -0,0 +1,32 @@ +From 9517df44c73576905041c0ad2d245d9286a574fe Mon Sep 17 00:00:00 2001 +From: Lubomír Sedlář +Date: May 07 2019 08:35:49 +0000 +Subject: config: Fix getting default branch in SCM dict + + +If user configures branch as explicit None, we want to default to HEAD +(which is most likely refs/heads/master in git). + +The original code was getting branch as None, which lead to wrong +resolver being used and the repo url being used as branch. + +Fixes: https://pagure.io/pungi/issue/1181 +Signed-off-by: Lubomír Sedlář + +--- + +diff --git a/pungi/checks.py b/pungi/checks.py +index 0df15dd..2f9478d 100644 +--- a/pungi/checks.py ++++ b/pungi/checks.py +@@ -305,7 +305,8 @@ def _extend_with_default_and_alias(validator_class, offline=False): + and "repo" in instance[property] + ): + instance[property]["branch"] = resolver( +- instance[property]["repo"], instance[property].get("branch", "HEAD") ++ instance[property]["repo"], ++ instance[property].get("branch") or "HEAD", + ) + + for error in _hook_errors(properties, instance, schema): + diff --git a/pungi.spec b/pungi.spec index 2fecec17..0272f32b 100644 --- a/pungi.spec +++ b/pungi.spec @@ -2,12 +2,14 @@ Name: pungi Version: 4.1.36 -Release: 1%{?dist} +Release: 2%{?dist} Summary: Distribution compose tool License: GPLv2 URL: https://pagure.io/pungi Source0: https://pagure.io/releases/%{name}/%{name}-%{version}.tar.bz2 +Patch0: https://pagure.io/pungi/pull-request/1183.patch +Patch1: https://pagure.io/pungi/pull-request/1184.patch BuildRequires: python3-nose BuildRequires: python3-mock @@ -202,6 +204,9 @@ nosetests-3 --exe %{_bindir}/%{name}-wait-for-signed-ostree-handler %changelog +* Tue May 07 2019 Lubomír Sedlář - 4.1.36-2 +- Backport fixes for cloning git repos + * Wed Apr 24 2019 Lubomír Sedlář - 4.1.36-1 - Extend "openssh" runroot_method to be able to execute "mock" (jkaluza) - osbs: Rework configuration for image pushes (lsedlar)