diff --git a/bears/vcs/actions/EditCommitMessageAction.py b/bears/vcs/actions/EditCommitMessageAction.py new file mode 100644 index 0000000000..26788a7d51 --- /dev/null +++ b/bears/vcs/actions/EditCommitMessageAction.py @@ -0,0 +1,21 @@ +import subprocess +from coalib.results.result_actions.ResultAction import ResultAction + + +class EditCommitMessageAction(ResultAction): + + SUCCESS_MESSAGE = 'Commit message edited successfully.' + + @staticmethod + def is_applicable(result, + original_file_dict, + file_diff_dict, + applied_actions=()): + return True + + def apply(self, result, original_file_dict, file_diff_dict): + """ + Edit (C)ommit Message [Note: This may rewrite your commit history] + """ + subprocess.check_call(['git', 'commit', '-o', '--amend']) + return file_diff_dict diff --git a/tests/vcs/actions/EditCommitMessageActionTest.py b/tests/vcs/actions/EditCommitMessageActionTest.py new file mode 100644 index 0000000000..dd39b61d42 --- /dev/null +++ b/tests/vcs/actions/EditCommitMessageActionTest.py @@ -0,0 +1,24 @@ +import unittest +from unittest.mock import patch +from coala_utils.ContextManagers import retrieve_stdout +from coalib.results.Result import Result +from bears.vcs.actions.EditCommitMessageAction import EditCommitMessageAction + + +class EditCommitMessageActionTest(unittest.TestCase): + + def setUp(self): + self.uut = EditCommitMessageAction() + self.result = Result('origin', 'message') + + def test_is_applicable(self): + self.assertTrue(self.uut.is_applicable(self.result, {}, {})) + + def test_apply(self): + with retrieve_stdout() as stdout: + patcher = ('bears.vcs.actions.EditCommitMessageAction.' + 'subprocess.check_call') + with patch(patcher): + ret = self.uut.apply(self.result, {}, {'file': 'diff'}) + self.assertEqual(ret, {'file': 'diff'}) + self.assertEqual(stdout.getvalue(), '')