Adds support for prepare-commit-msg hooks

Adds a prepare-commit-msg hook stage which allows for hooks which add
dynamic suggested/placeholder text to commit messages that an author can
use as a starting point for writing a commit message
This commit is contained in:
Marc Jay 2019-04-21 21:07:13 +01:00
parent 809b7482df
commit e60f541559
7 changed files with 142 additions and 6 deletions

View file

@ -557,7 +557,12 @@ def test_stages(cap_out, store, repo_with_passing_hook):
'language': 'pygrep',
'stages': [stage],
}
for i, stage in enumerate(('commit', 'push', 'manual'), 1)
for i, stage in enumerate(
(
'commit', 'push', 'manual', 'prepare-commit-msg',
'commit-msg',
), 1,
)
],
}
add_config_to_repo(repo_with_passing_hook, config)
@ -575,6 +580,8 @@ def test_stages(cap_out, store, repo_with_passing_hook):
assert _run_for_stage('commit').startswith(b'hook 1...')
assert _run_for_stage('push').startswith(b'hook 2...')
assert _run_for_stage('manual').startswith(b'hook 3...')
assert _run_for_stage('prepare-commit-msg').startswith(b'hook 4...')
assert _run_for_stage('commit-msg').startswith(b'hook 5...')
def test_commit_msg_hook(cap_out, store, commit_msg_repo):
@ -593,6 +600,25 @@ def test_commit_msg_hook(cap_out, store, commit_msg_repo):
)
def test_prepare_commit_msg_hook(cap_out, store, prepare_commit_msg_repo):
filename = '.git/COMMIT_EDITMSG'
with io.open(filename, 'w') as f:
f.write('This is the commit message')
_test_run(
cap_out,
store,
prepare_commit_msg_repo,
{'hook_stage': 'prepare-commit-msg', 'commit_msg_filename': filename},
expected_outputs=[b'Add "Signed off by:"', b'Passed'],
expected_ret=0,
stage=False,
)
with io.open(filename, 'rt') as f:
assert 'Signed off by: ' in f.read()
def test_local_hook_passes(cap_out, store, repo_with_passing_hook):
config = {
'repo': 'local',