From 0a2a54318ef5f57142a8fab05370e6824b0645da Mon Sep 17 00:00:00 2001 From: Florian Weimer Date: Oct 13 2025 09:59:52 +0000 Subject: Accept auto-generated sources in pre-push checks The patch-git tool creates source files during spec file parsing. With this change, the pre-push check recognizes the "auto-generated-/" source file prefix, so that patch-git can use it to bypass the check. (The rpmbuild tool ignores directory names.) Signed-off-by: Florian Weimer --- diff --git a/pyrpkg/__init__.py b/pyrpkg/__init__.py index a4e8b23..ee74fdc 100644 --- a/pyrpkg/__init__.py +++ b/pyrpkg/__init__.py @@ -4617,6 +4617,13 @@ class Commands(object): match = SpecFile.sourcefile_expression.match(line) if match: file_location = match.group('val') + if file_location.startswith('auto-generated/'): + # This source file is auto-generated during SRPM + # construction. It is not expected to be listed + # in source/checked into Git. Skip it for the + # pre-push check. + continue + # find out the format of the source file path. From URL use just the file name. # We want to keep hierarchy of the files if possible res = urllib.parse.urlparse(file_location) diff --git a/tests/commands/test_pre_push_check.py b/tests/commands/test_pre_push_check.py index 0e9aaf7..df7d2b4 100644 --- a/tests/commands/test_pre_push_check.py +++ b/tests/commands/test_pre_push_check.py @@ -105,3 +105,40 @@ Patch3: d.patch with open('sources', 'r') as f: expected_sources_content = f.read().strip() self.assertEqual(expected_sources_content, sources_content) + + def test_push_is_not_blocked_with_autogenerated_sources(self): + """ + Check that auto-generated/ source lines in the spec file + do not result in push failures. + """ + # Track SPEC and a.patch in Git. + spec_file = self.module + ".spec" + with open(spec_file, 'w') as f: + f.write(SPECFILE_TEMPLATE % '''Patch0: a.patch +Patch2: c.patch +Source1: auto-generated/patch-git-generated-commit.txt +''') + + for patch_file in ('a.patch', 'c.patch', + 'patch-git-generated-commit.txt'): + with open(patch_file, 'w') as f: + f.write(patch_file) + + # Track c.patch in sources + sources_file = SourcesFile(self.cmd.sources_filename, + self.cmd.source_entry_type) + file_hash = self.cmd.lookasidecache.hash_file('c.patch') + sources_file.add_entry(self.cmd.lookasidehash, 'c.patch', file_hash) + sources_file.write() + + self.cmd.repo.index.add([spec_file, 'a.patch', 'sources']) + self.cmd.repo.index.commit('add SPEC and patches') + + # The test attempts to connect to the lookaside cache. + + def patch_remote_file_exists_head(name, filename, hash, hashtype): + return filename == 'c.patch' + + with patch.object(self.cmd.lookasidecache, 'remote_file_exists_head', + patch_remote_file_exists_head): + self.cmd.pre_push_check("HEAD")