From 25862459b2265865ce1f5b2cd5e13b28c1028650 Mon Sep 17 00:00:00 2001 From: Chenxiong Qi Date: Jun 26 2018 09:42:43 +0000 Subject: Reserve README.md while import srpm Fixes #149 Signed-off-by: Chenxiong Qi --- diff --git a/pyrpkg/__init__.py b/pyrpkg/__init__.py index 15c550f..4e1c9c7 100644 --- a/pyrpkg/__init__.py +++ b/pyrpkg/__init__.py @@ -1585,6 +1585,11 @@ class Commands(object): # Need a way to make sure the srpm name matches the repo some how. + # 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'] + # Get a list of files we're currently tracking ourfiles = self.repo.git.ls_files().split('\n') if ourfiles == ['']: @@ -1604,6 +1609,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: + continue if file not in files: self.log.info("Removing no longer used file: %s", file) self.repo.index.remove([file]) diff --git a/tests/test_cli.py b/tests/test_cli.py index c50fdd4..0ff18cb 100644 --- a/tests/test_cli.py +++ b/tests/test_cli.py @@ -1234,6 +1234,8 @@ class TestImportSrpm(LookasideCacheMock, CliTestCase): def setUp(self): super(TestImportSrpm, self).setUp() + self.write_file(os.path.join(self.cloned_repo_path, 'README.md'), + content='Cool package') self.init_lookaside_cache() self.srcrpmdir = tempfile.mkdtemp(prefix='test-import-srpm-topdir-') @@ -1242,8 +1244,8 @@ class TestImportSrpm(LookasideCacheMock, CliTestCase): self.chaos_repo = tempfile.mkdtemp(prefix='rpkg-tests-chaos-repo-') cmds = ( ['git', 'init'], - ['touch', 'README.rst'], - ['git', 'add', 'README.rst'], + ['touch', 'README.md'], + ['git', 'add', 'README.md'], ['git', 'config', 'user.name', 'tester'], ['git', 'config', 'user.email', 'tester@example.com'], ['git', 'commit', '-m', '"Add README"'], @@ -1275,7 +1277,8 @@ class TestImportSrpm(LookasideCacheMock, CliTestCase): 'sources', 'docpkg.spec', 'hello-world.txt', - docpkg_gz], search_dir=target_repo) + docpkg_gz, + 'README.md'], search_dir=target_repo) self.assertFilesNotExist(['CHANGELOG.rst'], search_dir=target_repo) with open(os.path.join(target_repo, 'sources'), 'r') as f: self.assertEqual(