-
Notifications
You must be signed in to change notification settings - Fork 580
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
A new action for GitCommitBear when applied opens up a editor for user to edit commit message of the HEAD commit.
- Loading branch information
1 parent
dd44578
commit 629bc53
Showing
2 changed files
with
41 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
import subprocess | ||
from coalib.results.result_actions.ResultAction import ResultAction | ||
|
||
|
||
class EditCommitMessageAction(ResultAction): | ||
""" | ||
Opens an editor to edit the commit message of the HEAD commit. | ||
""" | ||
|
||
SUCCESS_MESSAGE = 'Commit message edited successfully.' | ||
|
||
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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(), '') |