#1183 util: Resolve ref if duplicate branches are present
Merged 4 years ago by lsedlar. Opened 4 years ago by lsedlar.
lsedlar/pungi resolve-multiple  into  master

file modified
+5 -2
@@ -263,7 +263,10 @@ 

  

      _, 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 @@ 

      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]

  

file modified
+14
@@ -48,6 +48,20 @@ 

          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')

  

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

rebased onto b2ca4432d2fed38a69abd2b711501e9324876488

4 years ago

rebased onto b0f0579

4 years ago

Pull-Request has been merged by lsedlar

4 years ago