test to ensure we accept abs filenames; use shlex so we handle quoted filenames; #152 #156

This commit is contained in:
Paul Gauthier 2023-09-29 15:02:45 -07:00
parent d2acb8e95e
commit 774589b376
2 changed files with 36 additions and 7 deletions

View file

@ -272,13 +272,12 @@ class Commands:
git_files = self.coder.repo.get_tracked_files() if self.coder.repo else []
all_matched_files = set()
for word in args.split():
for word in shlex.split(args):
fname = Path(self.coder.root) / word
if fname.exists():
if fname.is_file():
all_matched_files.add(str(fname))
continue
# else we fall through and glob will pickup all files within a dir
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
matched_files = self.glob_filtered_to_repo(word)
if matched_files:
@ -342,7 +341,7 @@ class Commands:
self.io.tool_output("Dropping all files from the chat session.")
self.coder.abs_fnames = set()
for word in args.split():
for word in shlex.split(args):
matched_files = self.glob_filtered_to_repo(word)
if not matched_files:

View file

@ -372,3 +372,33 @@ class TestCommands(TestCase):
commands.cmd_add(str(fname))
self.assertIn(str(fname.resolve()), coder.abs_fnames)
def test_cmd_add_abs_filename(self):
with ChdirTemporaryDirectory():
io = InputOutput(pretty=False, yes=False)
from aider.coders import Coder
coder = Coder.create(models.GPT35, None, io)
commands = Commands(io, coder)
fname = Path("file.txt")
fname.touch()
commands.cmd_add(str(fname.resolve()))
self.assertIn(str(fname.resolve()), coder.abs_fnames)
def test_cmd_add_quoted_filename(self):
with ChdirTemporaryDirectory():
io = InputOutput(pretty=False, yes=False)
from aider.coders import Coder
coder = Coder.create(models.GPT35, None, io)
commands = Commands(io, coder)
fname = Path("file with spaces.txt")
fname.touch()
commands.cmd_add(f'"{fname}"')
self.assertIn(str(fname.resolve()), coder.abs_fnames)