diff --git a/pre_commit/resources/hook-tmpl b/pre_commit/resources/hook-tmpl index cb25ec50..f455ca35 100755 --- a/pre_commit/resources/hook-tmpl +++ b/pre_commit/resources/hook-tmpl @@ -123,14 +123,15 @@ def _pre_push(stdin): elif remote_sha != Z40 and _rev_exists(remote_sha): opts = ('--origin', local_sha, '--source', remote_sha) else: - # First ancestor not found in remote - first_ancestor = subprocess.check_output(( - 'git', 'rev-list', '--max-count=1', '--topo-order', - '--reverse', local_sha, '--not', '--remotes={}'.format(remote), + # ancestors not found in remote + ancestors = subprocess.check_output(( + 'git', 'rev-list', local_sha, '--topo-order', '--reverse', + '--not', '--remotes={}'.format(remote), )).decode().strip() - if not first_ancestor: + if not ancestors: continue else: + first_ancestor = ancestors.splitlines()[0] cmd = ('git', 'rev-list', '--max-parents=0', local_sha) roots = set(subprocess.check_output(cmd).decode().splitlines()) if first_ancestor in roots: diff --git a/tests/commands/install_uninstall_test.py b/tests/commands/install_uninstall_test.py index 40d9beea..76ab14f3 100644 --- a/tests/commands/install_uninstall_test.py +++ b/tests/commands/install_uninstall_test.py @@ -527,11 +527,13 @@ def test_pre_push_integration_failing(tempdir_factory, store): install(Runner(path, C.CONFIG_FILE), store, hook_type='pre-push') # commit succeeds because pre-commit is only installed for pre-push assert _get_commit_output(tempdir_factory)[0] == 0 + assert _get_commit_output(tempdir_factory, touch_file='zzz')[0] == 0 retc, output = _get_push_output(tempdir_factory) assert retc == 1 assert 'Failing hook' in output assert 'Failed' in output + assert 'foo zzz' in output # both filenames should be printed assert 'hookid: failing_hook' in output