switch all to resolve

This commit is contained in:
Paul Gauthier 2023-07-07 16:59:35 -07:00
parent d5921f1a9a
commit 4b3fdc0f88
2 changed files with 12 additions and 8 deletions

View file

@ -255,17 +255,20 @@ class Commands:
matched_files = [word] matched_files = [word]
for matched_file in matched_files: 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: 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) 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: if abs_file_path not in self.coder.abs_fnames:
content = self.io.read_text(abs_file_path) content = self.io.read_text(abs_file_path)
if content is not None: if content is not None:
self.coder.abs_fnames.add(abs_file_path) self.coder.abs_fnames.add(abs_file_path)
self.io.tool_output(f"Added {matched_file} to the chat") self.io.tool_output(f"Added {matched_file} to the chat")
added_fnames.append(matched_file) added_fnames.append(matched_file)
else:
self.io.tool_error(f"Unable to read {matched_file}")
else: else:
self.io.tool_error(f"{matched_file} is already in the chat") 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}'") self.io.tool_error(f"No files matched '{word}'")
for matched_file in matched_files: for matched_file in matched_files:
self.coder.abs_fnames.remove(str(Path(matched_file).resolve())) abs_fname = str(Path(matched_file).resolve())
self.io.tool_output(f"Removed {matched_file} from the chat") 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): def cmd_run(self, args):
"Run a shell command and optionally add the output to the chat" "Run a shell command and optionally add the output to the chat"

View file

@ -59,11 +59,11 @@ class TestCommands(TestCase):
commands.cmd_add("*.py") commands.cmd_add("*.py")
# Check if the Python files have been added to the chat session # Check if the Python files have been added to the chat session
self.assertIn(os.path.abspath("test1.py"), coder.abs_fnames) self.assertIn(str(Path("test1.py").resolve()), coder.abs_fnames)
self.assertIn(os.path.abspath("test2.py"), 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 # 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): def test_cmd_add_no_match(self):
# Initialize the Commands and InputOutput objects # Initialize the Commands and InputOutput objects
@ -103,7 +103,6 @@ class TestCommands(TestCase):
# Call the cmd_drop method with a glob pattern # Call the cmd_drop method with a glob pattern
commands.cmd_drop("*2.py") 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.assertIn(str(Path("test1.py").resolve()), coder.abs_fnames)
self.assertNotIn(str(Path("test2.py").resolve()), coder.abs_fnames) self.assertNotIn(str(Path("test2.py").resolve()), coder.abs_fnames)