mirror of
https://github.com/Aider-AI/aider.git
synced 2025-06-01 18:25:00 +00:00
refactor: Simplify gitignore check and error handling logic
This commit is contained in:
parent
88ee089d86
commit
bc2f38c790
1 changed files with 19 additions and 16 deletions
|
@ -162,6 +162,8 @@ def check_gitignore(git_root, io, ask=True):
|
||||||
|
|
||||||
if not repo.ignored(".aider"):
|
if not repo.ignored(".aider"):
|
||||||
patterns_to_add.append(".aider*")
|
patterns_to_add.append(".aider*")
|
||||||
|
|
||||||
|
# only check .env if git_root/.env exists ai!
|
||||||
if not repo.ignored(".env"):
|
if not repo.ignored(".env"):
|
||||||
patterns_to_add.append(".env")
|
patterns_to_add.append(".env")
|
||||||
|
|
||||||
|
@ -183,24 +185,25 @@ def check_gitignore(git_root, io, ask=True):
|
||||||
content = ""
|
content = ""
|
||||||
except ANY_GIT_ERROR:
|
except ANY_GIT_ERROR:
|
||||||
return
|
return
|
||||||
if ask:
|
|
||||||
io.tool_output("You can skip this check with --no-gitignore")
|
|
||||||
if not io.confirm_ask(f"Add {', '.join(patterns_to_add)} to .gitignore (recommended)?"):
|
|
||||||
return
|
|
||||||
|
|
||||||
content += "\n".join(patterns_to_add) + "\n"
|
if ask:
|
||||||
|
io.tool_output("You can skip this check with --no-gitignore")
|
||||||
|
if not io.confirm_ask(f"Add {', '.join(patterns_to_add)} to .gitignore (recommended)?"):
|
||||||
|
return
|
||||||
|
|
||||||
try:
|
content += "\n".join(patterns_to_add) + "\n"
|
||||||
io.write_text(gitignore_file, content)
|
|
||||||
io.tool_output(f"Added {', '.join(patterns_to_add)} to .gitignore")
|
try:
|
||||||
except OSError as e:
|
io.write_text(gitignore_file, content)
|
||||||
io.tool_error(f"Error when trying to write to {gitignore_file}: {e}")
|
io.tool_output(f"Added {', '.join(patterns_to_add)} to .gitignore")
|
||||||
io.tool_output(
|
except OSError as e:
|
||||||
"Try running with appropriate permissions or manually add these patterns to"
|
io.tool_error(f"Error when trying to write to {gitignore_file}: {e}")
|
||||||
" .gitignore:"
|
io.tool_output(
|
||||||
)
|
"Try running with appropriate permissions or manually add these patterns to"
|
||||||
for pattern in patterns_to_add:
|
" .gitignore:"
|
||||||
io.tool_output(f" {pattern}")
|
)
|
||||||
|
for pattern in patterns_to_add:
|
||||||
|
io.tool_output(f" {pattern}")
|
||||||
|
|
||||||
|
|
||||||
def check_streamlit_install(io):
|
def check_streamlit_install(io):
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue