Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 7f0b427

Browse files
authored
Merge pull request #694 from pre-commit/fix_legacy_commit_msg_hooks
Fix legacy commit-msg hooks
2 parents 0a4fb17 + 49dc689 commit 7f0b427

2 files changed

Lines changed: 25 additions & 1 deletion

File tree

pre_commit/resources/hook-tmpl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ else
2727
fi
2828

2929
# Run the legacy pre-commit if it exists
30-
if [ -x "$HERE"/{hook_type}.legacy ] && ! "$HERE"/{hook_type}.legacy; then
30+
if [ -x "$HERE"/{hook_type}.legacy ] && ! "$HERE"/{hook_type}.legacy "$@"; then
3131
retv=1
3232
fi
3333

tests/commands/install_uninstall_test.py

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -611,6 +611,30 @@ def test_commit_msg_integration_passing(commit_msg_repo, tempdir_factory):
611611
assert first_line.endswith('...Passed')
612612

613613

614+
def test_commit_msg_legacy(commit_msg_repo, tempdir_factory):
615+
runner = Runner(commit_msg_repo, C.CONFIG_FILE)
616+
617+
hook_path = runner.get_hook_path('commit-msg')
618+
mkdirp(os.path.dirname(hook_path))
619+
with io.open(hook_path, 'w') as hook_file:
620+
hook_file.write(
621+
'#!/usr/bin/env bash\n'
622+
'set -eu\n'
623+
'test -e "$1"\n'
624+
'echo legacy\n',
625+
)
626+
make_executable(hook_path)
627+
628+
install(runner, hook_type='commit-msg')
629+
630+
msg = 'Hi\nSigned off by: asottile'
631+
retc, out = _get_commit_output(tempdir_factory, commit_msg=msg)
632+
assert retc == 0
633+
first_line, second_line = out.splitlines()[:2]
634+
assert first_line == 'legacy'
635+
assert second_line.startswith('Must have "Signed off by:"...')
636+
637+
614638
def test_install_disallow_mising_config(tempdir_factory):
615639
path = make_consuming_repo(tempdir_factory, 'script_hooks_repo')
616640
with cwd(path):

0 commit comments

Comments
 (0)