mirror of
https://github.com/Aider-AI/aider.git
synced 2025-05-29 08:44:59 +00:00
feat: add .env to gitignore check and update process
This commit is contained in:
parent
e487351c8d
commit
bde93903de
1 changed files with 14 additions and 7 deletions
|
@ -131,32 +131,39 @@ def check_gitignore(git_root, io, ask=True):
|
||||||
|
|
||||||
try:
|
try:
|
||||||
repo = git.Repo(git_root)
|
repo = git.Repo(git_root)
|
||||||
if repo.ignored(".aider"):
|
if repo.ignored(".aider") and repo.ignored(".env"):
|
||||||
return
|
return
|
||||||
except ANY_GIT_ERROR:
|
except ANY_GIT_ERROR:
|
||||||
pass
|
pass
|
||||||
|
|
||||||
pat = ".aider*"
|
patterns = [".aider*", ".env"]
|
||||||
|
patterns_to_add = []
|
||||||
|
|
||||||
gitignore_file = Path(git_root) / ".gitignore"
|
gitignore_file = Path(git_root) / ".gitignore"
|
||||||
if gitignore_file.exists():
|
if gitignore_file.exists():
|
||||||
content = io.read_text(gitignore_file)
|
content = io.read_text(gitignore_file)
|
||||||
if content is None:
|
if content is None:
|
||||||
return
|
return
|
||||||
if pat in content.splitlines():
|
existing_lines = content.splitlines()
|
||||||
return
|
for pat in patterns:
|
||||||
|
if pat not in existing_lines:
|
||||||
|
patterns_to_add.append(pat)
|
||||||
else:
|
else:
|
||||||
content = ""
|
content = ""
|
||||||
|
patterns_to_add = patterns
|
||||||
|
|
||||||
if ask and not io.confirm_ask(f"Add {pat} to .gitignore (recommended)?"):
|
if not patterns_to_add:
|
||||||
|
return
|
||||||
|
|
||||||
|
if ask and not io.confirm_ask(f"Add {', '.join(patterns_to_add)} to .gitignore (recommended)?"):
|
||||||
return
|
return
|
||||||
|
|
||||||
if content and not content.endswith("\n"):
|
if content and not content.endswith("\n"):
|
||||||
content += "\n"
|
content += "\n"
|
||||||
content += pat + "\n"
|
content += "\n".join(patterns_to_add) + "\n"
|
||||||
io.write_text(gitignore_file, content)
|
io.write_text(gitignore_file, content)
|
||||||
|
|
||||||
io.tool_output(f"Added {pat} to .gitignore")
|
io.tool_output(f"Added {', '.join(patterns_to_add)} to .gitignore")
|
||||||
|
|
||||||
|
|
||||||
def check_streamlit_install(io):
|
def check_streamlit_install(io):
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue