From 1bfd108593a268bdaf961249866f958081135ce1 Mon Sep 17 00:00:00 2001 From: Sam Duke Date: Wed, 24 Jan 2018 14:01:59 +0000 Subject: [PATCH 1/2] Properly detect if commit is a root commit Fix bad check for ancestor root commits. --- pre_commit/resources/pre-push-tmpl | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/pre_commit/resources/pre-push-tmpl b/pre_commit/resources/pre-push-tmpl index f866eeff..0a3dad57 100644 --- a/pre_commit/resources/pre-push-tmpl +++ b/pre_commit/resources/pre-push-tmpl @@ -8,7 +8,8 @@ do if [ -n "$first_ancestor" ]; then # Check that the ancestor has at least one parent git rev-list --max-parents=0 "$local_sha" | grep "$first_ancestor" > /dev/null - if [ $? -ne 0 ]; then + if [ $? -eq 0 ]; then + # Pushing the whole tree, including the root commit, so run on all files args="--all-files" else source=$(git rev-parse "$first_ancestor"^) From 4a6fdd4abef03e72ed09c8719554390c0d2ead3b Mon Sep 17 00:00:00 2001 From: Anthony Sottile Date: Wed, 24 Jan 2018 09:21:44 -0800 Subject: [PATCH 2/2] Add test for pushing to unrelated upstream --- tests/commands/install_uninstall_test.py | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/tests/commands/install_uninstall_test.py b/tests/commands/install_uninstall_test.py index 2ba5ce36..1659684a 100644 --- a/tests/commands/install_uninstall_test.py +++ b/tests/commands/install_uninstall_test.py @@ -564,6 +564,23 @@ def test_pre_push_integration_accepted(tempdir_factory): assert 'Passed' in output +def test_pre_push_new_upstream(tempdir_factory): + upstream = make_consuming_repo(tempdir_factory, 'script_hooks_repo') + upstream2 = git_dir(tempdir_factory) + path = tempdir_factory.get() + cmd_output('git', 'clone', upstream, path) + with cwd(path): + install(Runner(path, C.CONFIG_FILE), hook_type='pre-push') + assert _get_commit_output(tempdir_factory)[0] == 0 + + cmd_output('git', 'remote', 'rename', 'origin', 'upstream') + cmd_output('git', 'remote', 'add', 'origin', upstream2) + retc, output = _get_push_output(tempdir_factory) + assert retc == 0 + assert 'Bash hook' in output + assert 'Passed' in output + + def test_pre_push_integration_empty_push(tempdir_factory): upstream = make_consuming_repo(tempdir_factory, 'script_hooks_repo') path = tempdir_factory.get()