From 1450c4194e73a8f98d4afa8de1fcb1f4cf8e34fb Mon Sep 17 00:00:00 2001 From: "Paul Gauthier (aider)" Date: Wed, 13 Nov 2024 13:20:52 -0800 Subject: [PATCH] test: Add test to verify cmd_add respects .gitignore files --- tests/basic/test_commands.py | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/tests/basic/test_commands.py b/tests/basic/test_commands.py index 7288a8d6d..24ab00546 100644 --- a/tests/basic/test_commands.py +++ b/tests/basic/test_commands.py @@ -1210,6 +1210,30 @@ class TestCommands(TestCase): del commands del repo + def test_cmd_add_gitignored_file(self): + with GitTemporaryDirectory(): + repo = git.Repo() + + # Create and commit a .gitignore file + gitignore = Path(".gitignore") + gitignore.write_text("*.ignored\n") + repo.git.add(".gitignore") + repo.git.commit("-m", "Add .gitignore") + + # Create a file that matches the gitignore pattern + ignored_file = Path("test.ignored") + ignored_file.write_text("This should be ignored") + + io = InputOutput(pretty=False, fancy_input=False, yes=False) + coder = Coder.create(self.GPT35, None, io) + commands = Commands(io, coder) + + # Try to add the ignored file + commands.cmd_add(str(ignored_file)) + + # Verify the file was not added + self.assertEqual(len(coder.abs_fnames), 0) + def test_cmd_add_aiderignored_file(self): with GitTemporaryDirectory(): repo = git.Repo()