#3509 Enable fetching any ref from git repo
Merged a year ago by tkopecek. Opened 2 years ago by tkopecek.
tkopecek/koji issue3508  into  master

file modified
+22 -5
@@ -520,7 +520,7 @@ 

          # TODO: sanity check arguments

          sourcedir = '%s/%s' % (scmdir, self.module)

  

-         update_checkout_cmd = None

+         update_checkout_cmds = None

          update_checkout_dir = None

          env = None

  
@@ -575,10 +575,18 @@ 

                  checkout_path = os.path.basename(self.repository[:-4])

                  commonrepo = os.path.dirname(gitrepo[:-4]) + '/common.git'

  

+             # git-reset happily accepted origin/x spec, fetch has it split

+             if self.revision.startswith('origin/'):

+                 rev = self.revision[7:]

+             else:

+                 rev = self.revision

              sourcedir = '%s/%s' % (scmdir, checkout_path)

              module_checkout_cmd = ['git', 'clone', '-n', gitrepo, sourcedir]

              common_checkout_cmd = ['git', 'clone', commonrepo, 'common']

-             update_checkout_cmd = ['git', 'reset', '--hard', self.revision]

+             update_checkout_cmds = [

+                 ['git', 'fetch', 'origin', '%s:KOJI_FETCH_HEAD' % rev],

+                 ['git', 'reset', '--hard', 'KOJI_FETCH_HEAD']

+             ]

              update_checkout_dir = sourcedir

  

              # self.module may be empty, in which case the specfile should be in the top-level
@@ -605,10 +613,18 @@ 

                  checkout_path = os.path.basename(self.repository[:-4])

                  commonrepo = os.path.dirname(gitrepo[:-4]) + '/common.git'

  

+             # git-reset happily accepted origin/x spec, fetch has it split

+             if self.revision.startswith('origin/'):

+                 rev = self.revision[7:]

+             else:

+                 rev = self.revision

              sourcedir = '%s/%s' % (scmdir, checkout_path)

              module_checkout_cmd = ['git', 'clone', '-n', gitrepo, sourcedir]

              common_checkout_cmd = ['git', 'clone', commonrepo, 'common']

-             update_checkout_cmd = ['git', 'reset', '--hard', self.revision]

+             update_checkout_cmds = [

+                 ['git', 'fetch', 'origin', '%s:KOJI_FETCH_HEAD' % rev],

+                 ['git', 'reset', '--hard', 'KOJI_FETCH_HEAD']

+             ]

              update_checkout_dir = sourcedir

  

              # self.module may be empty, in which case the specfile should be in the top-level
@@ -643,7 +659,7 @@ 

          # perform checkouts

          _run(module_checkout_cmd, chdir=scmdir, fatal=True)

  

-         if update_checkout_cmd:

+         if update_checkout_cmds:

              # Currently only required for GIT checkouts

              # Run the command in the directory the source was checked out into

              if self.scmtype.startswith('GIT') and globals().get('KOJIKAMID'):
@@ -651,7 +667,8 @@ 

                       chdir=update_checkout_dir, fatal=True)

                  _run(['git', 'config', 'core.safecrlf', 'true'],

                       chdir=update_checkout_dir, fatal=True)

-             _run(update_checkout_cmd, chdir=update_checkout_dir, fatal=True)

+             for cmd in update_checkout_cmds:

+                 _run(cmd, chdir=update_checkout_dir, fatal=True)

  

          if self.use_common and not globals().get('KOJIKAMID'):

              _run(common_checkout_cmd, chdir=scmdir, fatal=True)

file modified
+16 -7
@@ -466,10 +466,13 @@ 

          cmd = ['git', 'clone', '-n', 'git://nocommon/koji.git', self.tempdir + '/koji']

          call1 = mock.call(self.session, cmd[0], cmd, self.logfile, self.uploadpath,

                            cwd=self.tempdir, logerror=1, append=False, env=None)

-         cmd = ['git', 'reset', '--hard', 'asdasd']

+         cmd = ['git', 'fetch', 'origin', 'asdasd:KOJI_FETCH_HEAD']

          call2 = mock.call(self.session, cmd[0], cmd, self.logfile, self.uploadpath,

                            cwd=self.tempdir + '/koji', logerror=1, append=True, env=None)

-         self.log_output.assert_has_calls([call1, call2])

+         cmd = ['git', 'reset', '--hard', 'KOJI_FETCH_HEAD']

+         call3 = mock.call(self.session, cmd[0], cmd, self.logfile, self.uploadpath,

+                           cwd=self.tempdir + '/koji', logerror=1, append=True, env=None)

+         self.log_output.assert_has_calls([call1, call2, call3])

  

      def test_checkout_gitssh_nocommon(self):

  
@@ -484,10 +487,13 @@ 

          cmd = ['git', 'clone', '-n', 'git+ssh://user@nocommon/koji.git', self.tempdir + '/koji']

          call1 = mock.call(self.session, cmd[0], cmd, self.logfile, self.uploadpath,

                            cwd=self.tempdir, logerror=1, append=False, env=None)

-         cmd = ['git', 'reset', '--hard', 'asdasd']

+         cmd = ['git', 'fetch', 'origin', 'asdasd:KOJI_FETCH_HEAD']

          call2 = mock.call(self.session, cmd[0], cmd, self.logfile, self.uploadpath,

                            cwd=self.tempdir + '/koji', logerror=1, append=True, env=None)

-         self.log_output.assert_has_calls([call1, call2])

+         cmd = ['git', 'reset', '--hard', 'KOJI_FETCH_HEAD']

+         call3 = mock.call(self.session, cmd[0], cmd, self.logfile, self.uploadpath,

+                           cwd=self.tempdir + '/koji', logerror=1, append=True, env=None)

+         self.log_output.assert_has_calls([call1, call2, call3])

  

      def test_checkout_git_common(self):

  
@@ -502,13 +508,16 @@ 

          cmd = ['git', 'clone', '-n', 'git://default/koji.git', self.tempdir + '/koji']

          call1 = mock.call(self.session, cmd[0], cmd, self.logfile, self.uploadpath,

                            cwd=self.tempdir, logerror=1, append=False, env=None)

-         cmd = ['git', 'reset', '--hard', 'asdasd']

+         cmd = ['git', 'fetch', 'origin', 'asdasd:KOJI_FETCH_HEAD']

          call2 = mock.call(self.session, cmd[0], cmd, self.logfile, self.uploadpath,

                            cwd=self.tempdir + '/koji', logerror=1, append=True, env=None)

-         cmd = ['git', 'clone', 'git://default/common.git', 'common']

+         cmd = ['git', 'reset', '--hard', 'KOJI_FETCH_HEAD']

          call3 = mock.call(self.session, cmd[0], cmd, self.logfile, self.uploadpath,

+                           cwd=self.tempdir + '/koji', logerror=1, append=True, env=None)

+         cmd = ['git', 'clone', 'git://default/common.git', 'common']

+         call4 = mock.call(self.session, cmd[0], cmd, self.logfile, self.uploadpath,

                            cwd=self.tempdir, logerror=1, append=True, env=None)

-         self.log_output.assert_has_calls([call1, call2, call3])

+         self.log_output.assert_has_calls([call1, call2, call3, call4])

  

      def test_checkout_error_in_command(self):

  

Missing origin?

+                 ['git', 'fetch', 'origin', self.revision, 'KOJI_FETCH_HEAD'],

1 new commit added

  • fix missing origin
2 years ago

Metadata Update from @tkopecek:
- Pull-request tagged with: testing-ready

2 years ago

rebased onto 53e36327d5bef02aaf8441beb466c3c17a644d27

2 years ago

1 new commit added

  • remove superfluous origin
2 years ago

rebased onto 4251d7f1ff7235f144b5395a4179331f8bf748eb

2 years ago

1 new commit added

  • fix typo
2 years ago

rebased onto 7d8d26972685868cc4369282252a159eacc4fdcc

2 years ago

2 new commits added

  • exception in case origin/ is part of ref
  • Enable fetching any ref from git repo
2 years ago

Metadata Update from @jobrauer:
- Pull-request tagged with: testing-done

a year ago

rebased onto ab9d15b

a year ago

Commit a848025 fixes this pull-request

Pull-Request has been merged by tkopecek

a year ago