From 6d5827643fd0a220729d86d5df6421893a944927 Mon Sep 17 00:00:00 2001 From: Paul Gauthier Date: Mon, 25 Sep 2023 14:55:00 -0700 Subject: [PATCH] don't try and commit unless there are changes #264 --- aider/repo.py | 5 ++++- tests/test_repo.py | 18 ++++++++++++++++++ 2 files changed, 22 insertions(+), 1 deletion(-) diff --git a/aider/repo.py b/aider/repo.py index a44f235b0..8be07641f 100644 --- a/aider/repo.py +++ b/aider/repo.py @@ -53,10 +53,13 @@ class GitRepo: if not fnames and not self.repo.is_dirty(): return + diffs = self.get_diffs(fnames) + if not diffs: + return + if message: commit_message = message else: - diffs = self.get_diffs(fnames) commit_message = self.get_commit_message(diffs, context) if not commit_message: diff --git a/tests/test_repo.py b/tests/test_repo.py index 77092c2da..66b12455b 100644 --- a/tests/test_repo.py +++ b/tests/test_repo.py @@ -194,3 +194,21 @@ class TestRepo(unittest.TestCase): raw_repo.git.commit("-m", "new") fnames = git_repo.get_tracked_files() self.assertIn(str(fname), fnames) + + @patch("aider.repo.simple_send_with_retries") + def test_noop_commit(self, mock_send): + mock_send.return_value = '"a good commit message"' + + with GitTemporaryDirectory(): + # new repo + raw_repo = git.Repo() + + # add it, but no commits at all in the raw_repo yet + fname = Path("file.txt") + fname.touch() + raw_repo.git.add(str(fname)) + raw_repo.git.commit("-m", "new") + + git_repo = GitRepo(InputOutput(), None, None) + + git_repo.commit(fnames=[str(fname)])