From 49dc689bf0b6d5c6f6903b970eb117318ec5d98f Mon Sep 17 00:00:00 2001 From: Anthony Sottile Date: Mon, 29 Jan 2018 21:47:35 -0800 Subject: [PATCH] Fix legacy commit-msg hooks --- pre_commit/resources/hook-tmpl | 2 +- tests/commands/install_uninstall_test.py | 24 ++++++++++++++++++++++++ 2 files changed, 25 insertions(+), 1 deletion(-) diff --git a/pre_commit/resources/hook-tmpl b/pre_commit/resources/hook-tmpl index ded311cf..b7f16231 100644 --- a/pre_commit/resources/hook-tmpl +++ b/pre_commit/resources/hook-tmpl @@ -27,7 +27,7 @@ else fi # Run the legacy pre-commit if it exists -if [ -x "$HERE"/{hook_type}.legacy ] && ! "$HERE"/{hook_type}.legacy; then +if [ -x "$HERE"/{hook_type}.legacy ] && ! "$HERE"/{hook_type}.legacy "$@"; then retv=1 fi diff --git a/tests/commands/install_uninstall_test.py b/tests/commands/install_uninstall_test.py index 1659684a..1469a3ee 100644 --- a/tests/commands/install_uninstall_test.py +++ b/tests/commands/install_uninstall_test.py @@ -611,6 +611,30 @@ def test_commit_msg_integration_passing(commit_msg_repo, tempdir_factory): assert first_line.endswith('...Passed') +def test_commit_msg_legacy(commit_msg_repo, tempdir_factory): + runner = Runner(commit_msg_repo, C.CONFIG_FILE) + + hook_path = runner.get_hook_path('commit-msg') + mkdirp(os.path.dirname(hook_path)) + with io.open(hook_path, 'w') as hook_file: + hook_file.write( + '#!/usr/bin/env bash\n' + 'set -eu\n' + 'test -e "$1"\n' + 'echo legacy\n', + ) + make_executable(hook_path) + + install(runner, hook_type='commit-msg') + + msg = 'Hi\nSigned off by: asottile' + retc, out = _get_commit_output(tempdir_factory, commit_msg=msg) + assert retc == 0 + first_line, second_line = out.splitlines()[:2] + assert first_line == 'legacy' + assert second_line.startswith('Must have "Signed off by:"...') + + def test_install_disallow_mising_config(tempdir_factory): path = make_consuming_repo(tempdir_factory, 'script_hooks_repo') with cwd(path):