From 19bb19e9f5e8b51923309158e50b67e2849bd8bb Mon Sep 17 00:00:00 2001 From: Evgeniy Alekseev Date: Fri, 10 Feb 2023 18:18:07 +0200 Subject: [PATCH] handle .gitignore file correctly in remote push trigger --- src/ahriman/core/gitremote/remote_push.py | 5 ++++- tests/ahriman/core/gitremote/test_remote_push.py | 11 ++++++++--- 2 files changed, 12 insertions(+), 4 deletions(-) diff --git a/src/ahriman/core/gitremote/remote_push.py b/src/ahriman/core/gitremote/remote_push.py index 24f6e3e9..401d05de 100644 --- a/src/ahriman/core/gitremote/remote_push.py +++ b/src/ahriman/core/gitremote/remote_push.py @@ -82,7 +82,10 @@ class RemotePush(LazyLogging): Sources.fetch(package_target_dir, package.remote) # ...and last, but not least, we remove the dot-git directory... for git_file in package_target_dir.glob(".git*"): - shutil.rmtree(package_target_dir / git_file) + if git_file.is_file(): + git_file.unlink() + else: + shutil.rmtree(git_file) # ...copy all patches... for patch in self.database.patches_get(package.base): filename = f"ahriman-{package.base}.patch" if patch.key is None else f"ahriman-{patch.key}.patch" diff --git a/tests/ahriman/core/gitremote/test_remote_push.py b/tests/ahriman/core/gitremote/test_remote_push.py index 41ad2f1e..0e06f5b8 100644 --- a/tests/ahriman/core/gitremote/test_remote_push.py +++ b/tests/ahriman/core/gitremote/test_remote_push.py @@ -22,8 +22,13 @@ def test_package_update(database: SQLite, configuration: Configuration, package_ patch2 = PkgbuildPatch("key", "value") local = Path("local") - glob_mock = mocker.patch("pathlib.Path.glob", return_value=[".git", ".gitignore"]) + mocker.patch( + "pathlib.Path.is_file", + autospec=True, + side_effect=lambda p: True if p == Path(".gitignore") else False) + glob_mock = mocker.patch("pathlib.Path.glob", return_value=[Path(".git"), Path(".gitignore")]) rmtree_mock = mocker.patch("shutil.rmtree") + unlink_mock = mocker.patch("pathlib.Path.unlink") fetch_mock = mocker.patch("ahriman.core.build_tools.sources.Sources.fetch") patches_mock = mocker.patch("ahriman.core.database.SQLite.patches_get", return_value=[patch1, patch2]) patches_write_mock = mocker.patch("ahriman.models.pkgbuild_patch.PkgbuildPatch.write") @@ -33,9 +38,9 @@ def test_package_update(database: SQLite, configuration: Configuration, package_ glob_mock.assert_called_once_with(".git*") rmtree_mock.assert_has_calls([ MockCall(local / package_ahriman.base, ignore_errors=True), - MockCall(local / package_ahriman.base / ".git"), - MockCall(local / package_ahriman.base / ".gitignore"), + MockCall(Path(".git")), ]) + unlink_mock.assert_called_once_with() fetch_mock.assert_called_once_with(pytest.helpers.anyvar(int), package_ahriman.remote) patches_mock.assert_called_once_with(package_ahriman.base) patches_write_mock.assert_has_calls([