From 90df92bffaca2817a3c4717c364ae82d92ca2fab Mon Sep 17 00:00:00 2001 From: Paul Gauthier Date: Fri, 14 Jul 2023 20:05:11 -0700 Subject: [PATCH] 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. --- aider/main.py | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/aider/main.py b/aider/main.py index c7364dc84..5a4fef84c 100644 --- a/aider/main.py +++ b/aider/main.py @@ -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