Blob Blame History Raw
From 87d4995b40fbcddac88fb21191eb2d5d1f248550 Mon Sep 17 00:00:00 2001
From: Ondrej Nosek <onosek@redhat.com>
Date: Tue, 11 Jul 2023 17:00:48 +0200
Subject: [PATCH 2/3] Support for checking exploded sources before push

pre-push-check now includes test whether source files listed
in a specfile come from additional sources.
This functionality is relevant only for some x-pkg tools, others
should not be affected.

JIRA: RHELCMP-11777

Signed-off-by: Ondrej Nosek <onosek@redhat.com>
---
 pyrpkg/__init__.py                    | 12 ++++++++++--
 tests/commands/test_pre_push_check.py |  4 ++--
 2 files changed, 12 insertions(+), 4 deletions(-)

diff --git a/pyrpkg/__init__.py b/pyrpkg/__init__.py
index b45ad8f..bc669b9 100644
--- a/pyrpkg/__init__.py
+++ b/pyrpkg/__init__.py
@@ -4468,6 +4468,10 @@ class Commands(object):
 
         return self._repo_name, version, release
 
+    # Works as virtual method. Other x-pkg tools can add their specific sources
+    def additional_source_entries(self):
+        return {}
+
     def pre_push_check(self, ref):
         show_hint = ('Hint: this check (.git/hooks/pre-push script) can be bypassed by adding '
                      'the argument \'--no-verify\' argument to the push command.')
@@ -4561,13 +4565,17 @@ class Commands(object):
         # 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")
 
+        # other x-pkg tools can add their specific sources
+        additional_entries = set(self.additional_source_entries())
+
         # check whether every source file is either listed in the 'sources' file or tracked in git
         for source_file in source_files:
             listed = source_file in sourcesf_entries
             tracked = source_file in repo_entries
-            if not (listed or tracked):
+            listed_additional = source_file in additional_entries
+            if not (listed or tracked or listed_additional):
                 self.log.error('Source file \'{0}\' was neither listed in the \'sources\' file '
-                               'nor tracked in git. '
+                               'nor tracked in git nor listed in additional sources. '
                                'Push operation was cancelled'.format(source_file))
                 self.log.warning(show_hint)
                 sys.exit(4)
diff --git a/tests/commands/test_pre_push_check.py b/tests/commands/test_pre_push_check.py
index ee151c1..79165ec 100644
--- a/tests/commands/test_pre_push_check.py
+++ b/tests/commands/test_pre_push_check.py
@@ -90,8 +90,8 @@ Patch3: d.patch
 
         self.assertEqual(exc.exception.code, 4)
         log_error.assert_called_once_with("Source file 'b.patch' was neither listed in the "
-                                          "'sources' file nor tracked in git. Push operation "
-                                          "was cancelled")
+                                          "'sources' file nor tracked in git nor listed "
+                                          "in additional sources. Push operation was cancelled")
 
         # Verify added files are committed but not pushed to origin
         local_repo = git.Repo(self.cloned_dir)
-- 
2.41.0