This commit is contained in:
Paul Gauthier 2023-07-10 15:10:23 -07:00
parent 79030d968f
commit a88b2a70e8
2 changed files with 23 additions and 24 deletions

View file

@ -238,6 +238,7 @@ class Commands:
git_added = []
git_files = self.coder.get_tracked_files()
expanded_files = set()
for word in args.split():
matched_files = self.glob_filtered_to_repo(word)
@ -246,24 +247,18 @@ class Commands:
self.io.tool_error(f"No files to add matching pattern: {word}")
else:
if Path(word).exists():
if Path(word).is_file():
matched_files = [word]
elif Path(word).is_dir():
matched_files = expand_subdir(word)
else:
self.io.tool_error(f"Can not add unknown file type: {word}")
elif self.io.confirm_ask(
f"No files matched '{word}'. Do you want to create the file?"
):
(Path(self.coder.root) / word).touch()
matched_files = [word]
expanded_files = []
for matched_file in matched_files:
if Path(matched_file).is_dir():
expanded_files += expand_subdir(matched_file)
expanded_files.update(expand_subdir(matched_file))
else:
expanded_files.append(matched_file)
expanded_files.add(matched_file)
for matched_file in expanded_files:
abs_file_path = self.coder.abs_root_path(matched_file)

View file

@ -89,17 +89,21 @@ class TestCommands(TestCase):
# Create a directory and add files to it
os.mkdir("test_dir")
os.mkdir("test_dir/another_dir")
with open("test_dir/test_file1.txt", "w") as f:
f.write("Test file 1")
with open("test_dir/test_file2.txt", "w") as f:
f.write("Test file 2")
with open("test_dir/another_dir/test_file.txt", "w") as f:
f.write("Test file 3")
# Call the cmd_add method with a directory
commands.cmd_add("test_dir")
commands.cmd_add("test_dir test_dir/test_file2.txt")
# Check if the files have been added to the chat session
self.assertIn(str(Path("test_dir/test_file1.txt").resolve()), coder.abs_fnames)
self.assertIn(str(Path("test_dir/test_file2.txt").resolve()), coder.abs_fnames)
self.assertIn(str(Path("test_dir/another_dir/test_file.txt").resolve()), coder.abs_fnames)
def test_cmd_drop_with_glob_patterns(self):
# Initialize the Commands and InputOutput objects