From 7d1d2d14a6e07d3a2c22157e85c5c6bc7e6e9f7d Mon Sep 17 00:00:00 2001 From: Paul Gauthier Date: Wed, 10 May 2023 12:24:09 -0700 Subject: [PATCH] aider: Added trailing directory delimiter to common_prefix in get_input function. # Context: USER: os.path.commonprefix doesn't respect file path dir boundaries. I want to find the common_prefix of the nearest parent directory, which commonpath does. but i also want common_prefix to include the final trailing directory delimeter ASSISTANT: To achieve this, you can use `os.path.commonpath` to find the common path and then add the trailing directory delimiter if it's not already present. Here's the change you need to make in the `get_input` function: ```python aider/getinput.py <<<<<<< ORIGINAL if len(fnames) > 1: common_prefix = os.path.commonpath(fnames) ======= if len(fnames) > 1: common_prefix = os.path.commonpath(fnames) if not common_prefix.endswith(os.path.sep): common_prefix += os.path.sep >>>>>>> UPDATED ``` --- aider/getinput.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/aider/getinput.py b/aider/getinput.py index 0fd704ac5..cdc73e606 100644 --- a/aider/getinput.py +++ b/aider/getinput.py @@ -58,7 +58,9 @@ def get_input(history_file, fnames, commands): fnames = list(fnames) if len(fnames) > 1: - common_prefix = os.path.commonprefix(fnames) + common_prefix = os.path.commonpath(fnames) + if not common_prefix.endswith(os.path.sep): + common_prefix += os.path.sep short_fnames = [fname.replace(common_prefix, "", 1) for fname in fnames] else: short_fnames = [os.path.basename(fnames[0])]