aider: Add .aider* to .gitignore if it is not already present.

# Aider chat conversation:

USER: do the TODO

ASSISTANT: To complete the TODO task in the `aider/main.py` file, we need to check if `.aider*` is in `.gitignore`, and if not, add it.

Here are the steps to do this:

1. Open the `.gitignore` file in the root directory of the git repository.
2. Read the contents of the file.
3. Check if `.aider*` is present in the file.
4. If not, append `.aider*` to the file and save it.

However, the code in `aider/main.py` does not currently have the ability to modify files. We need to add a function to handle this.

Here is the proposed change:

```python
aider/main.py
<<<<<<< ORIGINAL
    if git_root:
        # TODO: check if .aider* is in .gitignore, add it if not
        pass
=======
    if git_root:
        gitignore_file = Path(git_root) / ".gitignore"
        if gitignore_file.exists():
            with open(gitignore_file, "r") as file:
                content = file.read()
            if ".aider*" not in content:
                with open(gitignore_file, "a") as file:
                    file.write("\n.aider*")
        else:
            with open(gitignore_file, "w") as file:
                file.write(".aider*")
>>>>>>> UPDATED
```

This code will open the `.gitignore` file in the git root directory, check if `.aider*` is present, and if not, append it to the file. If the `.gitignore` file does not exist, it will create one and add `.aider*` to it.
This commit is contained in:
Paul Gauthier 2023-07-14 20:05:11 -07:00
parent 84da88feec
commit 90df92bffa

View file

@ -337,6 +337,19 @@ def main(args=None, input=None, output=None):
'Update git email with: git config --global user.email "you@example.com"'
)
io.tool_output("Git repository created in the current working directory.")
git_root = str(Path.cwd().resolve())
if git_root:
gitignore_file = Path(git_root) / ".gitignore"
if gitignore_file.exists():
with open(gitignore_file, "r") as file:
content = file.read()
if ".aider*" not in content:
with open(gitignore_file, "a") as file:
file.write("\n.aider*")
else:
with open(gitignore_file, "w") as file:
file.write(".aider*")
def scrub_sensitive_info(text):
# Replace sensitive information with placeholder