Handle the case where we fail to expand a dir

This commit is contained in:
Paul Gauthier 2023-07-11 08:12:18 -07:00
parent 4024713f31
commit c4e4d071fa

View file

@ -221,7 +221,8 @@ class Commands:
yield Completion(fname, start_position=-len(partial)) yield Completion(fname, start_position=-len(partial))
def glob_filtered_to_repo(self, pattern): def glob_filtered_to_repo(self, pattern):
raw_matched_files = Path(self.coder.root).glob(pattern) raw_matched_files = list(Path(self.coder.root).glob(pattern))
matched_files = [] matched_files = []
for fn in raw_matched_files: for fn in raw_matched_files:
matched_files += expand_subdir(fn.relative_to(self.coder.root)) matched_files += expand_subdir(fn.relative_to(self.coder.root))
@ -250,7 +251,10 @@ class Commands:
self.io.tool_error(f"No files to add matching pattern: {word}") self.io.tool_error(f"No files to add matching pattern: {word}")
else: else:
if Path(word).exists(): if Path(word).exists():
matched_files = [word] if Path(word).is_file():
matched_files = [word]
else:
self.io.tool_error(f"Unable to add: {word}")
elif self.io.confirm_ask( elif self.io.confirm_ask(
f"No files matched '{word}'. Do you want to create the file?" f"No files matched '{word}'. Do you want to create the file?"
): ):