fix: add files to git with force flag

It has been reported that AUR repositories might contain .gitignore,
which prevents PKGBUILD/.SRCINFO/whatever to be added without --force
flag. This commit simply adds force flag for all those operations, which
should be fine, because we don't commit wildcards

Closes #167
This commit is contained in:
arcanis committed 2026-10-17 12:17:40 +03:00
1 parent 0b371b3e77
commit 7f28e47ac4
2 files changed
+17 -3

No files matched your search

@@ -165,7 +165,7 @@ class Sources(LazyLogging):
# extract local files... # extract local files...
files = ["PKGBUILD", ".SRCINFO"] + [str(path) for path in Pkgbuild.local_files(sources_dir)] 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 # ...and commit them
instance.commit(sources_dir) instance.commit(sources_dir)
@@ -232,7 +232,7 @@ class Sources(LazyLogging):
git_url, branch = remote.git_source() git_url, branch = remote.git_source()
check_output(*instance.git(), "push", "--quiet", git_url, branch, cwd=sources_dir, logger=instance.logger) 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 track found files via git
@@ -241,6 +241,7 @@ class Sources(LazyLogging):
*pattern(str): glob patterns *pattern(str): glob patterns
intent_to_add(bool, optional): record only the fact that it will be added later, acts as 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) --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 # glob directory to find files which match the specified patterns
found_files: list[Path] = [] found_files: list[Path] = []
@@ -251,6 +252,8 @@ class Sources(LazyLogging):
self.logger.info("found matching files %s", found_files) self.logger.info("found matching files %s", found_files)
# add them to index # add them to index
args = ["--intent-to-add"] if intent_to_add else [] 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], check_output(*self.git(), "add", *args, *[str(fn.relative_to(sources_dir)) for fn in found_files],
cwd=sources_dir, logger=self.logger) cwd=sources_dir, logger=self.logger)
@@ -195,7 +195,7 @@ def test_init(sources: Sources, mocker: MockerFixture) -> None:
sources.init(local) sources.init(local)
check_output_mock.assert_called_once_with(*sources.git(), "init", "--quiet", "--initial-branch", check_output_mock.assert_called_once_with(*sources.git(), "init", "--quiet", "--initial-branch",
sources.DEFAULT_BRANCH, cwd=local, logger=pytest.helpers.anyvar(int)) 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) 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() 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: def test_commit(sources: Sources, mocker: MockerFixture) -> None:
""" """
must commit changes must commit changes