diff --git a/aider/commands.py b/aider/commands.py index 41a01bafb..633239ddf 100644 --- a/aider/commands.py +++ b/aider/commands.py @@ -592,7 +592,7 @@ class Commands: if abs_file_path in self.coder.abs_fnames: self.io.tool_error(f"{matched_file} is already in the chat") elif abs_file_path in self.coder.abs_read_only_fnames: - if self.coder.repo and matched_file in self.coder.repo.get_tracked_files(): + if self.coder.repo and self.coder.repo.path_in_repo(matched_file): self.coder.abs_read_only_fnames.remove(abs_file_path) self.coder.abs_fnames.add(abs_file_path) self.io.tool_output( diff --git a/tests/basic/test_commands.py b/tests/basic/test_commands.py index a0f34d427..07ea47c00 100644 --- a/tests/basic/test_commands.py +++ b/tests/basic/test_commands.py @@ -561,9 +561,24 @@ class TestCommands(TestCase): ) ) - # Mock the repo to simulate a tracked file - coder.repo = mock.MagicMock() - coder.repo.is_tracked_file.return_value = True + # Try to add the read-only file + commands.cmd_add(str(test_file)) + + # It's not in the repo, should not do anything + self.assertFalse( + any(os.path.samefile(str(test_file.resolve()), fname) for fname in coder.abs_fnames) + ) + self.assertTrue( + any( + os.path.samefile(str(test_file.resolve()), fname) + for fname in coder.abs_read_only_fnames + ) + ) + + + repo = git.Repo() + repo.git.add(str(test_file)) + repo.git.commit("-m", "initial") # Try to add the read-only file commands.cmd_add(str(test_file))