From 695299be3d006f0f5b7d6123fd3e3a0931881cf5 Mon Sep 17 00:00:00 2001 From: Paul Gauthier Date: Tue, 2 Jan 2024 09:04:44 -0800 Subject: [PATCH] aider: Update `changed_files_last_commit` to diff against the prior commit instead of the working directory. # Aider chat conversation: ASSISTANT: Here is the diff to update the `changed_files_last_commit` to diff against the prior commit: ```diff --- aider/commands.py +++ aider/commands.py @@ ... @@ def cmd_undo(self, args): "Undo the last git commit if it was done by aider" if not self.coder.repo: self.io.tool_error("No git repository found.") return last_commit = self.coder.repo.repo.head.commit - changed_files_last_commit = {item.a_path for item in last_commit.diff(None)} + changed_files_last_commit = {item.a_path for item in last_commit.diff(last_commit.parents[0])} dirty_files = [item.a_path for item in self.coder.repo.repo.index.diff(None)] dirty_files_in_last_commit = changed_files_last_commit.intersection(dirty_files) dump(changed_files_last_commit) dump(dirty_files) dump(dirty_files_in_last_commit) if dirty_files_in_last_commit: self.io.tool_error( "The repository has uncommitted changes in files that were modified in the last commit. " "Please commit or stash them before undoing." ) return @@ ... @@ ``` This change will ensure that `changed_files_last_commit` contains the files that were changed in the last commit by comparing it to its parent commit, rather than comparing it to the working directory. --- aider/commands.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/aider/commands.py b/aider/commands.py index d429bf5cd..f6e84a3c4 100644 --- a/aider/commands.py +++ b/aider/commands.py @@ -188,7 +188,7 @@ class Commands: last_commit = self.coder.repo.repo.head.commit dump(last_commit) - changed_files_last_commit = {item.a_path for item in last_commit.diff(None)} + changed_files_last_commit = {item.a_path for item in last_commit.diff(last_commit.parents[0])} dirty_files = [item.a_path for item in self.coder.repo.repo.index.diff(None)] dirty_files_in_last_commit = changed_files_last_commit.intersection(dirty_files) dump(changed_files_last_commit)