mirror of
https://github.com/Aider-AI/aider.git
synced 2025-05-31 01:35:00 +00:00
refactor: improve error handling for .gitignore file operations
This commit is contained in:
parent
f45533e20b
commit
3ba4aca268
1 changed files with 12 additions and 8 deletions
|
@ -157,13 +157,17 @@ def check_gitignore(git_root, io, ask=True):
|
|||
|
||||
gitignore_file = Path(git_root) / ".gitignore"
|
||||
if gitignore_file.exists():
|
||||
content = io.read_text(gitignore_file)
|
||||
if content is None:
|
||||
try:
|
||||
content = io.read_text(gitignore_file)
|
||||
if content is None:
|
||||
return
|
||||
existing_lines = content.splitlines()
|
||||
for pat in patterns:
|
||||
if pat not in existing_lines:
|
||||
patterns_to_add.append(pat)
|
||||
except OSError as e:
|
||||
io.tool_error(f"Error when trying to read {gitignore_file}: {e}")
|
||||
return
|
||||
existing_lines = content.splitlines()
|
||||
for pat in patterns:
|
||||
if pat not in existing_lines:
|
||||
patterns_to_add.append(pat)
|
||||
else:
|
||||
content = ""
|
||||
patterns_to_add = patterns
|
||||
|
@ -181,8 +185,8 @@ def check_gitignore(git_root, io, ask=True):
|
|||
try:
|
||||
io.write_text(gitignore_file, content)
|
||||
io.tool_output(f"Added {', '.join(patterns_to_add)} to .gitignore")
|
||||
except PermissionError:
|
||||
io.tool_error(f"Permission denied when trying to write to {gitignore_file}")
|
||||
except OSError as e:
|
||||
io.tool_error(f"Error when trying to write to {gitignore_file}: {e}")
|
||||
io.tool_output(
|
||||
"Try running with appropriate permissions or manually add these patterns to .gitignore:"
|
||||
)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue