From 9cf373039edc724334c04bbe53b7799edcea99d9 Mon Sep 17 00:00:00 2001 From: "Paul Gauthier (aider)" Date: Tue, 13 May 2025 13:41:58 -0700 Subject: [PATCH] test: Add test for skipping gitignored files on init --- tests/basic/test_coder.py | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/tests/basic/test_coder.py b/tests/basic/test_coder.py index e9cbe6842..362f863b6 100644 --- a/tests/basic/test_coder.py +++ b/tests/basic/test_coder.py @@ -834,6 +834,34 @@ two self.assertNotIn(fname2, str(coder.abs_fnames)) self.assertNotIn(fname3, str(coder.abs_fnames)) + def test_skip_gitignored_files_on_init(self): + with GitTemporaryDirectory() as tmpdir: + repo_path = Path(tmpdir) + repo = git.Repo.init(repo_path) + + ignored_file = repo_path / "ignored_by_git.txt" + ignored_file.write_text("This file should be ignored by git.") + + regular_file = repo_path / "regular_file.txt" + regular_file.write_text("This is a regular file.") + + gitignore_content = "ignored_by_git.txt\n" + (repo_path / ".gitignore").write_text(gitignore_content) + + repo.index.add([str(regular_file), ".gitignore"]) + repo.index.commit("Initial commit with gitignore and regular file") + + mock_io = MagicMock() + mock_io.tool_warning = MagicMock() + + fnames_to_add = [str(ignored_file), str(regular_file)] + + coder = Coder.create(self.GPT35, None, mock_io, fnames=fnames_to_add, repo=repo) + + self.assertNotIn(str(ignored_file.resolve()), coder.abs_fnames) + self.assertIn(str(regular_file.resolve()), coder.abs_fnames) + mock_io.tool_warning.assert_any_call(f"Skipping {ignored_file.name} that matches gitignore spec.") + def test_check_for_urls(self): io = InputOutput(yes=True) coder = Coder.create(self.GPT35, None, io=io)