mirror of
https://github.com/Aider-AI/aider.git
synced 2025-05-29 08:44:59 +00:00
catch git errors for commit and diff
This commit is contained in:
parent
2cfdd7ab5b
commit
bd012d63e9
1 changed files with 38 additions and 30 deletions
|
@ -121,7 +121,10 @@ class GitRepo:
|
|||
if fnames:
|
||||
fnames = [str(self.abs_root_path(fn)) for fn in fnames]
|
||||
for fname in fnames:
|
||||
try:
|
||||
self.repo.git.add(fname)
|
||||
except ANY_GIT_ERROR as err:
|
||||
self.io.tool_error(f"Unable to add {fname}: {err}")
|
||||
cmd += ["--"] + fnames
|
||||
else:
|
||||
cmd += ["-a"]
|
||||
|
@ -137,10 +140,14 @@ class GitRepo:
|
|||
original_auther_name_env = os.environ.get("GIT_AUTHOR_NAME")
|
||||
os.environ["GIT_AUTHOR_NAME"] = committer_name
|
||||
|
||||
try:
|
||||
self.repo.git.commit(cmd)
|
||||
commit_hash = self.get_head_commit_sha(short=True)
|
||||
self.io.tool_output(f"Commit {commit_hash} {commit_message}", bold=True)
|
||||
|
||||
return commit_hash, commit_message
|
||||
except ANY_GIT_ERROR as err:
|
||||
self.io.tool_error(f"Unable to commit: {err}")
|
||||
finally:
|
||||
# Restore the env
|
||||
|
||||
if self.attribute_committer:
|
||||
|
@ -155,8 +162,6 @@ class GitRepo:
|
|||
else:
|
||||
del os.environ["GIT_AUTHOR_NAME"]
|
||||
|
||||
return commit_hash, commit_message
|
||||
|
||||
def get_rel_repo_dir(self):
|
||||
try:
|
||||
return os.path.relpath(self.repo.git_dir, os.getcwd())
|
||||
|
@ -210,7 +215,7 @@ class GitRepo:
|
|||
current_branch_has_commits = any(commits)
|
||||
except ANY_GIT_ERROR:
|
||||
pass
|
||||
except TypeError:
|
||||
except (TypeError,) + ANY_GIT_ERROR:
|
||||
pass
|
||||
|
||||
if not fnames:
|
||||
|
@ -221,6 +226,7 @@ class GitRepo:
|
|||
if not self.path_in_repo(fname):
|
||||
diffs += f"Added {fname}\n"
|
||||
|
||||
try:
|
||||
if current_branch_has_commits:
|
||||
args = ["HEAD", "--"] + list(fnames)
|
||||
diffs += self.repo.git.diff(*args)
|
||||
|
@ -233,6 +239,8 @@ class GitRepo:
|
|||
diffs += self.repo.git.diff(*wd_args)
|
||||
|
||||
return diffs
|
||||
except ANY_GIT_ERROR as err:
|
||||
self.io.tool_error(f"Unable to diff: {err}")
|
||||
|
||||
def diff_commits(self, pretty, from_commit, to_commit):
|
||||
args = []
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue