test: Add test to verify cmd_add respects .gitignore files

This commit is contained in:
Paul Gauthier (aider) 2024-11-13 13:20:52 -08:00
parent bc82baa968
commit 1450c4194e

View file

@ -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()