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.
This commit is contained in:
Paul Gauthier 2023-05-26 15:43:49 -07:00
parent e17265c998
commit 05e976a2b6

View file

@ -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",