From 05e976a2b6629c4f48a367edf9cf9ceafaff99e2 Mon Sep 17 00:00:00 2001 From: Paul Gauthier Date: Fri, 26 May 2023 15:43:49 -0700 Subject: [PATCH] aider: Set default configuration file path to prefer Git repository root and fallback to user's home directory. # Context: USER: give them both, preferring the git one ASSISTANT: To set the default configuration file path to prefer the Git repository root and fallback to the user's home directory, update the `aider/main.py` file with the following changes: ```python aider/main.py <<<<<<< ORIGINAL git_root = get_git_root() if git_root: default_config_file = os.path.join(git_root, ".aider.conf.yml") else: default_config_file = os.path.expanduser("~/.aider.conf.yml") ======= default_config_files = [ os.path.expanduser("~/.aider.conf.yml"), ] git_root = get_git_root() if git_root: default_config_files.insert(0, os.path.join(git_root, ".aider.conf.yml")) >>>>>>> UPDATED ``` ```python aider/main.py <<<<<<< ORIGINAL parser = configargparse.ArgumentParser( description="aider - chat with GPT about your code", add_config_file_help=True, default_config_files=[default_config_file], ) ======= parser = configargparse.ArgumentParser( description="aider - chat with GPT about your code", add_config_file_help=True, default_config_files=default_config_files, ) >>>>>>> UPDATED ``` These changes will set the `default_config_files` list to include both the Git repository root and the user's home directory, with preference given to the Git repository root. --- aider/main.py | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/aider/main.py b/aider/main.py index 925d8a444..8416c68b8 100644 --- a/aider/main.py +++ b/aider/main.py @@ -20,16 +20,18 @@ def main(args=None, input=None, output=None): except git.InvalidGitRepositoryError: return None +default_config_files = [ + os.path.expanduser("~/.aider.conf.yml"), +] + git_root = get_git_root() if git_root: - default_config_file = os.path.join(git_root, ".aider.conf.yml") -else: - default_config_file = os.path.expanduser("~/.aider.conf.yml") + default_config_files.insert(0, os.path.join(git_root, ".aider.conf.yml")) parser = configargparse.ArgumentParser( description="aider - chat with GPT about your code", add_config_file_help=True, - default_config_files=[default_config_file], + default_config_files=default_config_files, ) parser.add_argument( "files",