diff --git a/ahriman-core/src/ahriman/core/build_tools/sources.py b/ahriman-core/src/ahriman/core/build_tools/sources.py index 93ba7e4e..cf680e17 100644 --- a/ahriman-core/src/ahriman/core/build_tools/sources.py +++ b/ahriman-core/src/ahriman/core/build_tools/sources.py @@ -165,7 +165,7 @@ class Sources(LazyLogging): # extract local files... files = ["PKGBUILD", ".SRCINFO"] + [str(path) for path in Pkgbuild.local_files(sources_dir)] - instance.add(sources_dir, *files) + instance.add(sources_dir, *files, force=True) # ...and commit them instance.commit(sources_dir) @@ -232,7 +232,7 @@ class Sources(LazyLogging): git_url, branch = remote.git_source() check_output(*instance.git(), "push", "--quiet", git_url, branch, cwd=sources_dir, logger=instance.logger) - def add(self, sources_dir: Path, *pattern: str, intent_to_add: bool = False) -> None: + def add(self, sources_dir: Path, *pattern: str, intent_to_add: bool = False, force: bool = False) -> None: """ track found files via git @@ -241,6 +241,7 @@ class Sources(LazyLogging): *pattern(str): glob patterns intent_to_add(bool, optional): record only the fact that it will be added later, acts as --intent-to-add git flag (Default value = False) + force(bool, optional): allow adding ignored files (Default value = False) """ # glob directory to find files which match the specified patterns found_files: list[Path] = [] @@ -251,6 +252,8 @@ class Sources(LazyLogging): self.logger.info("found matching files %s", found_files) # add them to index args = ["--intent-to-add"] if intent_to_add else [] + if force: + args.append("--force") check_output(*self.git(), "add", *args, *[str(fn.relative_to(sources_dir)) for fn in found_files], cwd=sources_dir, logger=self.logger) diff --git a/ahriman-core/tests/ahriman/core/build_tools/test_sources.py b/ahriman-core/tests/ahriman/core/build_tools/test_sources.py index ab48105e..43a22170 100644 --- a/ahriman-core/tests/ahriman/core/build_tools/test_sources.py +++ b/ahriman-core/tests/ahriman/core/build_tools/test_sources.py @@ -195,7 +195,7 @@ def test_init(sources: Sources, mocker: MockerFixture) -> None: sources.init(local) check_output_mock.assert_called_once_with(*sources.git(), "init", "--quiet", "--initial-branch", sources.DEFAULT_BRANCH, cwd=local, logger=pytest.helpers.anyvar(int)) - add_mock.assert_called_once_with(local, "PKGBUILD", ".SRCINFO", "local") + add_mock.assert_called_once_with(local, "PKGBUILD", ".SRCINFO", "local", force=True) commit_mock.assert_called_once_with(local) @@ -347,6 +347,17 @@ def test_add_skip(sources: Sources, mocker: MockerFixture) -> None: check_output_mock.assert_not_called() +def test_add_force(sources: Sources, tmp_path: Path, mocker: MockerFixture) -> None: + """ + must add files to git with --force flag + """ + mocker.patch("pathlib.Path.glob", return_value=[Path("local/1"), Path("local/2")]) + check_output_mock = mocker.patch("ahriman.core.build_tools.sources.check_output") + + sources.add(Path("local"), "PKGBUILD", force=True) + assert "--force" in check_output_mock.call_args.args + + def test_commit(sources: Sources, mocker: MockerFixture) -> None: """ must commit changes