#185 Resolve branch in ksurl
Merged 9 years ago by ausil. Opened 9 years ago by lsedlar.
lsedlar/pungi resolve-branch  into  master

file modified
+26
@@ -289,6 +289,32 @@ 

          signing_key_password_file = '~/password_for_fedora-24_key'

  

  

+ Git URLs

+ ========

+ 

+ In multiple places the config requires URL of a Git repository to download

+ kickstart file from. This URL is passed on to *Koji*. It is possible to which

+ commit to use using this syntax: ::

+ 

+     git://git.example.com/git/repo-name.git?#<rev_spec>

+ 

+ The ``<rev_spec>`` pattern can be replaced with actual commit SHA, a tag name,

+ ``HEAD`` to indicate that tip of default branch should be used or

+ ``origin/<branch_name>`` to use tip of arbitrary branch.

+ 

+ If the URL specifies a branch or ``HEAD``, *Pungi* will replace it with the

+ actual commit SHA. This will later show up in *Koji* tasks and help with

+ tracing what particular inputs were used.

+ 

+ .. note::

+ 

+     The ``origin`` must be specified because of the way *Koji* works with the

+     repository. It will clone the repository then switch to requested state

+     with ``git reset --hard REF``. Since no local branches are created, we need

+     to use full specification including the name of the remote.

+ 

+ 

+ 

  Createrepo Settings

  ===================

  

file modified
+14 -4
@@ -220,9 +220,18 @@ 

      return bool(get_arch_variant_data(conf, 'multilib', arch, None))

  

  

+ def _get_git_ref(fragment):

+     if fragment == 'HEAD':

+         return fragment

+     if fragment.startswith('origin/'):

+         branch = fragment.split('/', 1)[1]

+         return 'refs/heads/' + branch

+     return None

+ 

+ 

  def resolve_git_url(url):

-     """Given a url to a Git repo specifying HEAD as a ref, replace that

-     specifier with actual SHA1 of the commit.

+     """Given a url to a Git repo specifying HEAD or origin/<branch> as a ref,

+     replace that specifier with actual SHA1 of the commit.

  

      Otherwise, the original URL will be returned.

  
@@ -230,11 +239,12 @@ 

      run git command.

      """

      r = urlparse.urlsplit(url)

-     if r.fragment != 'HEAD':

+     ref = _get_git_ref(r.fragment)

+     if not ref:

          return url

  

      baseurl = urlparse.urlunsplit((r.scheme, r.netloc, r.path, '', ''))

-     _, output = run(['git', 'ls-remote', baseurl, r.fragment])

+     _, output = run(['git', 'ls-remote', baseurl, ref])

  

      lines = [line for line in output.split('\n') if line]

      if len(lines) != 1:

file modified
+9
@@ -26,6 +26,15 @@ 

          run.assert_called_once_with(['git', 'ls-remote', 'https://git.example.com/repo.git', 'HEAD'])

  

      @mock.patch('pungi.util.run')

+     def test_successful_resolve_branch(self, run):

+         run.return_value = (0, 'CAFEBABE\trefs/heads/f24\n')

+ 

+         url = util.resolve_git_url('https://git.example.com/repo.git?somedir#origin/f24')

+ 

+         self.assertEqual(url, 'https://git.example.com/repo.git?somedir#CAFEBABE')

+         run.assert_called_once_with(['git', 'ls-remote', 'https://git.example.com/repo.git', 'refs/heads/f24'])

+ 

+     @mock.patch('pungi.util.run')

      def test_resolve_missing_spec(self, run):

          url = util.resolve_git_url('https://git.example.com/repo.git')

  

no initial comment

Pull-Request has been rebased

9 years ago

koji needs the ?# not #
git://git.example.com/git/repo-name.git?#<rev_spec>

Pull-Request has been updated

9 years ago

Oh, I forgot about that. I'm not clear why that is (in my opinion the question mark should have no effect on anything), but I changed it.

Pull-Request has been merged by ausil

9 years ago