diff --git a/aider/coder.py b/aider/coder.py index 9c47b9f13..24e87517f 100755 --- a/aider/coder.py +++ b/aider/coder.py @@ -516,7 +516,9 @@ class Coder: ) return - commit_message = commit_message.strip().strip('"').strip() + commit_message = commit_message.strip() + if commit_message and commit_message[0] == '"' and commit_message[-1] == '"': + commit_message = commit_message[1:-1].strip() if interrupted: self.io.tool_error( diff --git a/tests/test_coder.py b/tests/test_coder.py index 863998ac6..86e7487b6 100644 --- a/tests/test_coder.py +++ b/tests/test_coder.py @@ -76,5 +76,38 @@ class TestCoder(unittest.TestCase): # Assert that the returned message is the expected one self.assertEqual(result, "a good commit message") + def test_get_commit_message_strip_quotes(self): + # Mock the IO object + mock_io = MagicMock() + + # Initialize the Coder object with the mocked IO and mocked repo + coder = Coder(io=mock_io, openai_api_key="fake_key") + + # Mock the send method to return a tuple with a message and False + coder.send = MagicMock(return_value=('"a good commit message"', False)) + + # Call the get_commit_message method with dummy diff and context + result = coder.get_commit_message("dummy diff", "dummy context") + + # Assert that the returned message is the expected one + self.assertEqual(result, "a good commit message") + + def test_get_commit_message_no_strip_unmatched_quotes(self): + # Mock the IO object + mock_io = MagicMock() + + # Initialize the Coder object with the mocked IO and mocked repo + coder = Coder(io=mock_io, openai_api_key="fake_key") + + # Mock the send method to return a tuple with a message and False + coder.send = MagicMock(return_value=('a good "commit message"', False)) + + # Call the get_commit_message method with dummy diff and context + result = coder.get_commit_message("dummy diff", "dummy context") + + # Assert that the returned message is the expected one + self.assertEqual(result, 'a good "commit message"') + + if __name__ == "__main__": unittest.main()