From e610e5bd0a5854c0a93337a57ab43d095a3dba49 Mon Sep 17 00:00:00 2001 From: Paul Gauthier Date: Tue, 30 Apr 2024 15:50:24 -0700 Subject: [PATCH] Handle existing dirnames with [globby] chars, with test #195 --- aider/commands.py | 10 ++++++---- tests/test_commands.py | 17 +++++++++++++++++ 2 files changed, 23 insertions(+), 4 deletions(-) diff --git a/aider/commands.py b/aider/commands.py index 40581b0f9..3b6f359d5 100644 --- a/aider/commands.py +++ b/aider/commands.py @@ -349,10 +349,12 @@ class Commands: self.io.tool_error(f"Skipping {fname} that matches aiderignore spec.") continue - if fname.exists() and fname.is_file(): - all_matched_files.add(str(fname)) - continue - # an existing dir will fall through and get recursed by glob + if fname.exists(): + if fname.is_file(): + all_matched_files.add(str(fname)) + continue + # an existing dir, escape any special chars so they won't be globs + word = re.sub(r"([\*\?\[\]])", r"[\1]", word) matched_files = self.glob_filtered_to_repo(word) if matched_files: diff --git a/tests/test_commands.py b/tests/test_commands.py index 1751a359d..8cc67b6d8 100644 --- a/tests/test_commands.py +++ b/tests/test_commands.py @@ -386,6 +386,23 @@ class TestCommands(TestCase): self.assertIn(str(fname.resolve()), coder.abs_fnames) + def test_cmd_add_dirname_with_special_chars(self): + with ChdirTemporaryDirectory(): + io = InputOutput(pretty=False, yes=False) + from aider.coders import Coder + + coder = Coder.create(self.GPT35, None, io) + commands = Commands(io, coder) + + dname = Path("with[brackets]") + dname.mkdir() + fname = dname / "filename.txt" + fname.touch() + + commands.cmd_add(str(dname)) + + self.assertIn(str(fname.resolve()), coder.abs_fnames) + def test_cmd_add_abs_filename(self): with ChdirTemporaryDirectory(): io = InputOutput(pretty=False, yes=False)