diff --git a/aider/coders/base_coder.py b/aider/coders/base_coder.py index 6fc81c8f2..a3129ae15 100755 --- a/aider/coders/base_coder.py +++ b/aider/coders/base_coder.py @@ -712,11 +712,11 @@ class Coder: # Check if the file is already in the repo if self.repo: - tracked_files = set(self.get_tracked_files()) + tracked_files = set(self.repo.get_tracked_files()) relative_fname = self.get_rel_fname(full_path) if relative_fname not in tracked_files and self.io.confirm_ask(f"Add {path} to git?"): if not self.dry_run: - self.repo.git.add(full_path) + self.repo.repo.git.add(full_path) if write_content: self.io.write_text(full_path, write_content) diff --git a/tests/test_coder.py b/tests/test_coder.py index a9ffaeca5..72b247727 100644 --- a/tests/test_coder.py +++ b/tests/test_coder.py @@ -22,6 +22,37 @@ class TestCoder(unittest.TestCase): def tearDown(self): self.patcher.stop() + def test_allowed_to_edit(self): + with GitTemporaryDirectory(): + repo = git.Repo(Path.cwd()) + fname = Path("foo.txt") + fname.touch() + repo.git.add(str(fname)) + repo.git.commit("-m", "init") + + io = InputOutput(yes=True) + # Initialize the Coder object with the mocked IO and mocked repo + coder = Coder.create(models.GPT4, None, io, fnames=["foo.txt"]) + + self.assertTrue(coder.allowed_to_edit("foo.txt")) + self.assertTrue(coder.allowed_to_edit("new.txt")) + + def test_allowed_to_edit_no(self): + with GitTemporaryDirectory(): + repo = git.Repo(Path.cwd()) + fname = Path("foo.txt") + fname.touch() + repo.git.add(str(fname)) + repo.git.commit("-m", "init") + + # say NO + io = InputOutput(yes=False) + + coder = Coder.create(models.GPT4, None, io, fnames=["foo.txt"]) + + self.assertTrue(coder.allowed_to_edit("foo.txt")) + self.assertFalse(coder.allowed_to_edit("new.txt")) + def test_get_last_modified(self): # Mock the IO object mock_io = MagicMock()