mirror of
https://github.com/Aider-AI/aider.git
synced 2025-06-01 02:05:00 +00:00
aider: Refactored check_gitignore
function to use gitpython
library to check if the .aider
pattern is already ignored by the repository before adding it to .gitignore
.
# Aider chat conversation: USER: in `check_gitignore` use gitpython to see if the repo is already ignoring `.aider`. if so, don't add anything to gitignore ASSISTANT: To implement this change, we need to modify the `check_gitignore` function in the `aider/main.py` file. We will use the `gitpython` library to check if the `.aider` pattern is already ignored by the repository. If it is, we won't add anything to the `.gitignore` file. Here are the steps we need to take: 1. Import the `git` module at the top of the file. 2. In the `check_gitignore` function, create a `git.Repo` object for the current repository. 3. Use the `Repo.ignored` method to check if the `.aider` pattern is already ignored. 4. Only add the `.aider` pattern to the `.gitignore` file if it's not already ignored. Here is the *edit block* for this change: ```python aider/main.py <<<<<<< HEAD def check_gitignore(git_root, io, ask=True): if not git_root: return pat = ".aider*" gitignore_file = Path(git_root) / ".gitignore" if gitignore_file.exists(): content = io.read_text(gitignore_file) if pat in content.splitlines(): return else: content = "" if ask and not io.confirm_ask(f"Add {pat} to .gitignore (recommended)?"): return if content and not content.endswith("\n"): content += "\n" content += pat + "\n" io.write_text(gitignore_file, content) io.tool_output(f"Added {pat} to .gitignore") ======= import git def check_gitignore(git_root, io, ask=True): if not git_root: return pat = ".aider*" gitignore_file = Path(git_root) / ".gitignore" if gitignore_file.exists(): content = io.read_text(gitignore_file) if pat in content.splitlines(): return else: content = "" repo = git.Repo(git_root) if repo.is_ignored(pat): return if ask and not io.confirm_ask(f"Add {pat} to .gitignore (recommended)?"): return if content and not content.endswith("\n"): content += "\n" content += pat + "\n" io.write_text(gitignore_file, content) io.tool_output(f"Added {pat} to .gitignore") >>>>>>> updated ``` Please note that this change assumes that the `gitpython` library is already installed in your environment. If it's not, you will need to install it using pip (`pip install gitpython`).
This commit is contained in:
parent
14eb12364d
commit
19e4787502
1 changed files with 6 additions and 0 deletions
|
@ -70,6 +70,8 @@ def setup_git(git_root, io):
|
||||||
return repo.working_tree_dir
|
return repo.working_tree_dir
|
||||||
|
|
||||||
|
|
||||||
|
import git
|
||||||
|
|
||||||
def check_gitignore(git_root, io, ask=True):
|
def check_gitignore(git_root, io, ask=True):
|
||||||
if not git_root:
|
if not git_root:
|
||||||
return
|
return
|
||||||
|
@ -84,6 +86,10 @@ def check_gitignore(git_root, io, ask=True):
|
||||||
else:
|
else:
|
||||||
content = ""
|
content = ""
|
||||||
|
|
||||||
|
repo = git.Repo(git_root)
|
||||||
|
if repo.is_ignored(pat):
|
||||||
|
return
|
||||||
|
|
||||||
if ask and not io.confirm_ask(f"Add {pat} to .gitignore (recommended)?"):
|
if ask and not io.confirm_ask(f"Add {pat} to .gitignore (recommended)?"):
|
||||||
return
|
return
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue