From 4b3fdc0f8874cbd201205f31e2063190772508b6 Mon Sep 17 00:00:00 2001 From: Paul Gauthier Date: Fri, 7 Jul 2023 16:59:35 -0700 Subject: [PATCH] switch all to resolve --- aider/commands.py | 13 +++++++++---- tests/test_commands.py | 7 +++---- 2 files changed, 12 insertions(+), 8 deletions(-) diff --git a/aider/commands.py b/aider/commands.py index ce73fd72e..3a70659c5 100644 --- a/aider/commands.py +++ b/aider/commands.py @@ -255,17 +255,20 @@ class Commands: matched_files = [word] for matched_file in matched_files: + abs_file_path = str((Path(self.coder.root) / matched_file).resolve()) + if self.coder.repo and matched_file not in git_files: - self.coder.repo.git.add(os.path.join(self.coder.root, matched_file)) + self.coder.repo.git.add(abs_file_path) git_added.append(matched_file) - abs_file_path = str((Path(self.coder.root) / matched_file).resolve()) if abs_file_path not in self.coder.abs_fnames: content = self.io.read_text(abs_file_path) if content is not None: self.coder.abs_fnames.add(abs_file_path) self.io.tool_output(f"Added {matched_file} to the chat") added_fnames.append(matched_file) + else: + self.io.tool_error(f"Unable to read {matched_file}") else: self.io.tool_error(f"{matched_file} is already in the chat") @@ -307,8 +310,10 @@ class Commands: self.io.tool_error(f"No files matched '{word}'") for matched_file in matched_files: - self.coder.abs_fnames.remove(str(Path(matched_file).resolve())) - self.io.tool_output(f"Removed {matched_file} from the chat") + abs_fname = str(Path(matched_file).resolve()) + if abs_fname in self.coder.abs_fnames: + self.coder.abs_fnames.remove(abs_fname) + self.io.tool_output(f"Removed {matched_file} from the chat") def cmd_run(self, args): "Run a shell command and optionally add the output to the chat" diff --git a/tests/test_commands.py b/tests/test_commands.py index fcad63676..c43826419 100644 --- a/tests/test_commands.py +++ b/tests/test_commands.py @@ -59,11 +59,11 @@ class TestCommands(TestCase): commands.cmd_add("*.py") # Check if the Python files have been added to the chat session - self.assertIn(os.path.abspath("test1.py"), coder.abs_fnames) - self.assertIn(os.path.abspath("test2.py"), coder.abs_fnames) + self.assertIn(str(Path("test1.py").resolve()), coder.abs_fnames) + self.assertIn(str(Path("test2.py").resolve()), coder.abs_fnames) # Check if the text file has not been added to the chat session - self.assertNotIn(os.path.abspath("test.txt"), coder.abs_fnames) + self.assertNotIn(str(Path("test.txt").resolve()), coder.abs_fnames) def test_cmd_add_no_match(self): # Initialize the Commands and InputOutput objects @@ -103,7 +103,6 @@ class TestCommands(TestCase): # Call the cmd_drop method with a glob pattern commands.cmd_drop("*2.py") - # Check if the Python files have been removed from the chat session self.assertIn(str(Path("test1.py").resolve()), coder.abs_fnames) self.assertNotIn(str(Path("test2.py").resolve()), coder.abs_fnames)