From 583c3285ec94303b9f94c9c75d67b44859db3a8b Mon Sep 17 00:00:00 2001 From: Paul Gauthier Date: Wed, 18 Oct 2023 10:31:45 -0700 Subject: [PATCH] added tests, fixed bug --- aider/repo.py | 3 +++ tests/test_repo.py | 38 ++++++++++++++++++++++++++++++++++++++ 2 files changed, 41 insertions(+) diff --git a/aider/repo.py b/aider/repo.py index f3a3818d4..d8adf1653 100644 --- a/aider/repo.py +++ b/aider/repo.py @@ -202,6 +202,9 @@ class GitRepo: if not self.aider_ignore_file: return fnames + if not Path(self.aider_ignore_file).is_file(): + return fnames + with open(self.aider_ignore_file, "r") as f: ignore_spec = pathspec.PathSpec.from_lines("gitwildmatch", f) diff --git a/tests/test_repo.py b/tests/test_repo.py index 66b12455b..066e40467 100644 --- a/tests/test_repo.py +++ b/tests/test_repo.py @@ -171,6 +171,44 @@ class TestRepo(unittest.TestCase): self.assertIn(str(fname), fnames) self.assertIn(str(fname2), fnames) + def test_get_tracked_files_with_aiderignore(self): + with GitTemporaryDirectory(): + # new repo + raw_repo = git.Repo() + + # add it, but no commits at all in the raw_repo yet + fname = Path("new.txt") + fname.touch() + raw_repo.git.add(str(fname)) + + git_repo = GitRepo(InputOutput(), None, None, ".aiderignore") + + # better be there + fnames = git_repo.get_tracked_files() + self.assertIn(str(fname), fnames) + + # commit it, better still be there + raw_repo.git.commit("-m", "new") + fnames = git_repo.get_tracked_files() + self.assertIn(str(fname), fnames) + + # new file, added but not committed + fname2 = Path("new2.txt") + fname2.touch() + raw_repo.git.add(str(fname2)) + + # both should be there + fnames = git_repo.get_tracked_files() + self.assertIn(str(fname), fnames) + self.assertIn(str(fname2), fnames) + + Path(".aiderignore").write_text("new.txt\n") + + # new.txt should be gone! + fnames = git_repo.get_tracked_files() + self.assertNotIn(str(fname), fnames) + self.assertIn(str(fname2), fnames) + def test_get_tracked_files_from_subdir(self): with GitTemporaryDirectory(): # new repo