From c348e1f16ce4bd94adfe1aa4e1abbf14b92a6f8a Mon Sep 17 00:00:00 2001 From: Ondrej Nosek Date: Jul 19 2019 12:08:22 +0000 Subject: Do not delete files related to gating on import When `rhpkg import` is used, it will delete files that are not used in the imported SRPM but are tracked in git. Now there is an exception for 'gating.yaml' also 'tests/' subdirectory - these files are kept. JIRA: COMPOSE-3672 Signed-off-by: Ondrej Nosek --- diff --git a/pyrpkg/__init__.py b/pyrpkg/__init__.py index 4756eea..9859e82 100644 --- a/pyrpkg/__init__.py +++ b/pyrpkg/__init__.py @@ -1845,7 +1845,9 @@ class Commands(object): # Some repositories are created with an initial commit with some files # created and committed. Files listed here are what should be reserved # while importing a SRPM. - reserved_ourfiles = ['README.md'] + # The list also contains files, that are important and should + # not be removed by import command. + reserved_ourfiles = ['README.md', 'gating.yaml', 'tests/*'] # Get a list of files we're currently tracking ourfiles = self.repo.git.ls_files().split('\n') @@ -1866,7 +1868,8 @@ class Commands(object): # Look through our files and if it isn't in the new files, remove it. for file in ourfiles: - if file in reserved_ourfiles: + # matches 'file' to any 'reserved_ourfiles' pattern? + if any(filter(lambda pattern: fnmatch.fnmatch(file, pattern), reserved_ourfiles)): continue if file not in files: self.log.info("Removing no longer used file: %s", file) diff --git a/tests/test_cli.py b/tests/test_cli.py index 4ed9ff5..c6b2f7a 100644 --- a/tests/test_cli.py +++ b/tests/test_cli.py @@ -1432,6 +1432,30 @@ class TestImportSrpm(LookasideCacheMock, CliTestCase): self.assert_import_srpm(self.chaos_repo) self.assert_import_srpm(self.cloned_repo_path) + def test_import_gating_exception(self): + # Add two additional files to the repo. Former (gating.yaml) is listed among reserved + # files, latter is not and after import it should be removed from the repo. + cmds = ( + ['touch', 'gating.yaml'], + ['touch', 'the_file_is_not_in_reserved.yaml'], + ['git', 'add', 'gating.yaml'], + ['git', 'add', 'the_file_is_not_in_reserved.yaml'], + ['git', 'commit', '--amend', '--no-edit'], # non-interactive amend + ) + for cmd in cmds: + self.run_cmd(cmd, cwd=self.chaos_repo, stdout=subprocess.PIPE, stderr=subprocess.PIPE) + + cli_cmd = ['rpkg', '--path', self.chaos_repo, '--name', 'docpkg', + 'import', '--skip-diffs', self.srpm_file] + + with patch('sys.argv', new=cli_cmd): + cli = self.new_cli() + with patch('pyrpkg.lookaside.CGILookasideCache.upload', self.lookasidecache_upload): + cli.import_srpm() + + self.assertFilesExist(['gating.yaml'], search_dir=self.chaos_repo) + self.assertFilesNotExist(['the_file_is_not_in_reserved.yaml'], search_dir=self.chaos_repo) + class TestMockbuild(CliTestCase): """Test mockbuild command"""