Merge pull request #694 from pre-commit/fix_legacy_commit_msg_hooks

Fix legacy commit-msg hooks
This commit is contained in:
Anthony Sottile 2018-01-29 22:17:59 -08:00 committed by GitHub
commit 7f0b427b74
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 25 additions and 1 deletions

View file

@ -27,7 +27,7 @@ else
fi fi
# Run the legacy pre-commit if it exists # 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 retv=1
fi fi

View file

@ -611,6 +611,30 @@ def test_commit_msg_integration_passing(commit_msg_repo, tempdir_factory):
assert first_line.endswith('...Passed') 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): def test_install_disallow_mising_config(tempdir_factory):
path = make_consuming_repo(tempdir_factory, 'script_hooks_repo') path = make_consuming_repo(tempdir_factory, 'script_hooks_repo')
with cwd(path): with cwd(path):