Update commands to use the underlying repo

This commit is contained in:
Paul Gauthier 2023-07-21 13:01:48 -03:00
parent 74875eac6e
commit 01ea691957

View file

@ -171,10 +171,10 @@ class Commands:
) )
return return
local_head = self.coder.repo.git.rev_parse("HEAD") local_head = self.coder.repo.repo.git.rev_parse("HEAD")
current_branch = self.coder.repo.active_branch.name current_branch = self.coder.repo.repo.active_branch.name
try: try:
remote_head = self.coder.repo.git.rev_parse(f"origin/{current_branch}") remote_head = self.coder.repo.repo.git.rev_parse(f"origin/{current_branch}")
has_origin = True has_origin = True
except git.exc.GitCommandError: except git.exc.GitCommandError:
has_origin = False has_origin = False
@ -187,14 +187,14 @@ class Commands:
) )
return return
last_commit = self.coder.repo.head.commit last_commit = self.coder.repo.repo.head.commit
if ( if (
not last_commit.message.startswith("aider:") not last_commit.message.startswith("aider:")
or last_commit.hexsha[:7] != self.coder.last_aider_commit_hash or last_commit.hexsha[:7] != self.coder.last_aider_commit_hash
): ):
self.io.tool_error("The last commit was not made by aider in this chat session.") self.io.tool_error("The last commit was not made by aider in this chat session.")
return return
self.coder.repo.git.reset("--hard", "HEAD~1") self.coder.repo.repo.git.reset("--hard", "HEAD~1")
self.io.tool_output( self.io.tool_output(
f"{last_commit.message.strip()}\n" f"{last_commit.message.strip()}\n"
f"The above commit {self.coder.last_aider_commit_hash} " f"The above commit {self.coder.last_aider_commit_hash} "
@ -215,7 +215,7 @@ class Commands:
return return
commits = f"{self.coder.last_aider_commit_hash}~1" commits = f"{self.coder.last_aider_commit_hash}~1"
diff = self.coder.get_diffs( diff = self.coder.repo.get_diffs(
self.coder.pretty, self.coder.pretty,
commits, commits,
self.coder.last_aider_commit_hash, self.coder.last_aider_commit_hash,
@ -278,7 +278,7 @@ class Commands:
abs_file_path = self.coder.abs_root_path(matched_file) abs_file_path = self.coder.abs_root_path(matched_file)
if self.coder.repo and matched_file not in git_files: if self.coder.repo and matched_file not in git_files:
self.coder.repo.git.add(abs_file_path) self.coder.repo.repo.git.add(abs_file_path)
git_added.append(matched_file) git_added.append(matched_file)
if abs_file_path in self.coder.abs_fnames: if abs_file_path in self.coder.abs_fnames:
@ -295,8 +295,8 @@ class Commands:
if self.coder.repo and git_added: if self.coder.repo and git_added:
git_added = " ".join(git_added) git_added = " ".join(git_added)
commit_message = f"aider: Added {git_added}" commit_message = f"aider: Added {git_added}"
self.coder.repo.git.commit("-m", commit_message, "--no-verify") self.coder.repo.repo.git.commit("-m", commit_message, "--no-verify")
commit_hash = self.coder.repo.head.commit.hexsha[:7] commit_hash = self.coder.repo.repo.head.commit.hexsha[:7]
self.io.tool_output(f"Commit {commit_hash} {commit_message}") self.io.tool_output(f"Commit {commit_hash} {commit_message}")
if not added_fnames: if not added_fnames: