From 5dc7bc055e86afaa1d0f55eed7e25b4192072b9a Mon Sep 17 00:00:00 2001 From: Paul Gauthier Date: Sun, 16 Jul 2023 13:42:36 -0300 Subject: [PATCH] Whitelist more /cmds for no dirty commit --- HISTORY.md | 4 ++++ aider/coders/base_coder.py | 4 ++-- tests/test_coder.py | 20 ++++++++++++++++++++ 3 files changed, 26 insertions(+), 2 deletions(-) diff --git a/HISTORY.md b/HISTORY.md index 94b5fefa5..c48c726a9 100644 --- a/HISTORY.md +++ b/HISTORY.md @@ -1,5 +1,9 @@ # Release history +### GitHub main branch + +- + ### v0.9.0 - Support for the OpenAI models in [Azure](https://aider.chat/docs/faq.html#azure) diff --git a/aider/coders/base_coder.py b/aider/coders/base_coder.py index f4b000acf..5ceea559f 100755 --- a/aider/coders/base_coder.py +++ b/aider/coders/base_coder.py @@ -407,8 +407,8 @@ class Coder: if cmds: matching_commands, _, _ = cmds if len(matching_commands) == 1: - cmd = matching_commands[0] - if cmd in ("/exit", "/commit"): + cmd = matching_commands[0][1:] + if cmd in "add clear commit diff drop exit help ls tokens".split(): return if not self.dirty_commits: diff --git a/tests/test_coder.py b/tests/test_coder.py index 80a92f902..41ae7e644 100644 --- a/tests/test_coder.py +++ b/tests/test_coder.py @@ -24,6 +24,26 @@ class TestCoder(unittest.TestCase): def tearDown(self): self.patcher.stop() + def test_should_dirty_commit(self): + # Mock the IO object + mock_io = MagicMock() + + with GitTemporaryDirectory(): + repo = git.Repo(Path.cwd()) + fname = Path("new.txt") + fname.touch() + repo.git.add(str(fname)) + repo.git.commit("-m", "new") + + # Initialize the Coder object with the mocked IO and mocked repo + coder = Coder.create(models.GPT4, None, mock_io) + + fname.write_text("hi") + self.assertTrue(coder.should_dirty_commit("hi")) + + self.assertFalse(coder.should_dirty_commit("/exit")) + self.assertFalse(coder.should_dirty_commit("/help")) + def test_check_for_file_mentions(self): # Mock the IO object mock_io = MagicMock()