| |
@@ -4442,30 +4442,41 @@
|
| |
sys.exit(1)
|
| |
|
| |
try:
|
| |
+ clone_dir = tempfile.mkdtemp(prefix="pre_push_hook_")
|
| |
+ for cmd in [
|
| |
+ ('git', 'clone', self.path, clone_dir),
|
| |
+ ('git', 'checkout', ref),
|
| |
+ ]:
|
| |
+ ret, _, _ = self._run_command(cmd, cwd=clone_dir,
|
| |
+ # suppress unwanted printing of command line messages
|
| |
+ return_stdout=True, return_stderr=True)
|
| |
+ if ret != 0:
|
| |
+ self.log.error('Command \'{0}\' failed. Push operation '
|
| |
+ 'was cancelled.'.format(' '.join(cmd)))
|
| |
+ self.log.warning(show_hint)
|
| |
+ sys.exit(2)
|
| |
+
|
| |
+ # get all source files from the specfile (including patches)
|
| |
# Assume, that specfile names are same in the active branch
|
| |
# and in the pushed branch (git checkout f37 && git push origin rawhide)
|
| |
# in this case 'f37' is active branch and 'rawhide' is pushed branch.
|
| |
specfile_path_absolute = os.path.join(self.layout.specdir, self.spec)
|
| |
# convert to relative path
|
| |
specfile_path = os.path.relpath(specfile_path_absolute, start=self.path)
|
| |
- spec_content = self.repo.git.cat_file("-p", "{0}:{1}".format(ref, specfile_path))
|
| |
- except Exception:
|
| |
- # It might be the case of an empty commit
|
| |
- self.log.warning('Specfile doesn\'t exist. Push operation continues.')
|
| |
- return
|
| |
-
|
| |
- # load specfile content from pushed branch and save it into a temporary file
|
| |
- with tempfile.NamedTemporaryFile(mode="w+") as temporary_spec:
|
| |
- temporary_spec.write(spec_content)
|
| |
- temporary_spec.flush()
|
| |
- # get all source files from the specfile (including patches)
|
| |
- cmd = ('spectool', '-l', temporary_spec.name)
|
| |
- ret, stdout, _ = self._run_command(cmd, return_text=True, return_stdout=True)
|
| |
+ cmd = ['spectool', '-l', os.path.join(clone_dir, specfile_path)]
|
| |
+ # extract just '--define' arguments from rpmdefines
|
| |
+ for opt, val in zip(self.rpmdefines[0::2], self.rpmdefines[1::2]):
|
| |
+ if opt == '--define':
|
| |
+ cmd.extend((opt, val))
|
| |
+ ret, stdout, _ = self._run_command(cmd, cwd=clone_dir,
|
| |
+ return_text=True, return_stdout=True)
|
| |
if ret != 0:
|
| |
self.log.error('Command \'{0}\' failed. Push operation '
|
| |
'was cancelled.'.format(' '.join(cmd)))
|
| |
self.log.warning(show_hint)
|
| |
- sys.exit(2)
|
| |
+ sys.exit(3)
|
| |
+ finally:
|
| |
+ self._cleanup_tmp_dir(clone_dir)
|
| |
|
| |
source_files = []
|
| |
# extract source files from the spectool's output
|
| |
@@ -4490,22 +4501,16 @@
|
| |
sources_file_path_absolute = self.sources_filename
|
| |
# convert to relative path
|
| |
sources_file_path = os.path.relpath(sources_file_path_absolute, start=self.path)
|
| |
- sources_file_content = self.repo.git.cat_file(
|
| |
- '-p', '{0}:{1}'.format(ref, sources_file_path))
|
| |
+
|
| |
+ # parse 'sources' files content
|
| |
+ sourcesf = SourcesFile(sources_file_path, self.source_entry_type)
|
| |
+ sourcesf_entries = set(item.file for item in sourcesf.entries)
|
| |
except Exception:
|
| |
self.log.warning('\'sources\' file doesn\'t exist. Push operation continues.')
|
| |
# NOTE: check doesn't fail when 'sources' file doesn't exist. Just skips the rest.
|
| |
# it might be the case of the push without 'sources' = retiring the repository
|
| |
return
|
| |
|
| |
- # load 'sources' file content from pushed branch and save it into a temporary file
|
| |
- with tempfile.NamedTemporaryFile(mode="w+") as temporary_sources_file:
|
| |
- temporary_sources_file.write(sources_file_content)
|
| |
- temporary_sources_file.flush()
|
| |
- # parse 'sources' files content
|
| |
- sourcesf = SourcesFile(temporary_sources_file.name, self.source_entry_type)
|
| |
- sourcesf_entries = set(item.file for item in sourcesf.entries)
|
| |
-
|
| |
# list of all files (their relative paths) in the commit
|
| |
repo_entries = set(item.path for item in commit.tree.traverse() if item.type != "tree")
|
| |
|
| |
@@ -4518,7 +4523,7 @@
|
| |
'nor tracked in git. '
|
| |
'Push operation was cancelled'.format(source_file))
|
| |
self.log.warning(show_hint)
|
| |
- sys.exit(3)
|
| |
+ sys.exit(4)
|
| |
|
| |
# verify all file entries in 'sources' were uploaded to the lookaside cache
|
| |
for entry in sourcesf.entries:
|
| |
@@ -4532,6 +4537,6 @@
|
| |
self.log.error('Source file (or tarball) \'{}\' wasn\'t uploaded to the lookaside '
|
| |
'cache. Push operation was cancelled.'.format(filename))
|
| |
self.log.warning(show_hint)
|
| |
- sys.exit(4)
|
| |
+ sys.exit(5)
|
| |
|
| |
return 0 # The push operation continues
|
| |
JIRA: RHELCMP-11466
Fixes: #672
To get all defined source files and patches from the specfile, the 'spectool' utility needs '--define' argument(s) to set specific paths for the repository.
Signed-off-by: Ondrej Nosek onosek@redhat.com