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

Skip to content

Commit c733c39

Browse files
authored
Merge pull request #692 from samskiter/patch-1
Properly detect if commit is a root commit
2 parents 51ac0e8 + 4a6fdd4 commit c733c39

2 files changed

Lines changed: 19 additions & 1 deletion

File tree

pre_commit/resources/pre-push-tmpl

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,8 @@ do
88
if [ -n "$first_ancestor" ]; then
99
# Check that the ancestor has at least one parent
1010
git rev-list --max-parents=0 "$local_sha" | grep "$first_ancestor" > /dev/null
11-
if [ $? -ne 0 ]; then
11+
if [ $? -eq 0 ]; then
12+
# Pushing the whole tree, including the root commit, so run on all files
1213
args="--all-files"
1314
else
1415
source=$(git rev-parse "$first_ancestor"^)

tests/commands/install_uninstall_test.py

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -564,6 +564,23 @@ def test_pre_push_integration_accepted(tempdir_factory):
564564
assert 'Passed' in output
565565

566566

567+
def test_pre_push_new_upstream(tempdir_factory):
568+
upstream = make_consuming_repo(tempdir_factory, 'script_hooks_repo')
569+
upstream2 = git_dir(tempdir_factory)
570+
path = tempdir_factory.get()
571+
cmd_output('git', 'clone', upstream, path)
572+
with cwd(path):
573+
install(Runner(path, C.CONFIG_FILE), hook_type='pre-push')
574+
assert _get_commit_output(tempdir_factory)[0] == 0
575+
576+
cmd_output('git', 'remote', 'rename', 'origin', 'upstream')
577+
cmd_output('git', 'remote', 'add', 'origin', upstream2)
578+
retc, output = _get_push_output(tempdir_factory)
579+
assert retc == 0
580+
assert 'Bash hook' in output
581+
assert 'Passed' in output
582+
583+
567584
def test_pre_push_integration_empty_push(tempdir_factory):
568585
upstream = make_consuming_repo(tempdir_factory, 'script_hooks_repo')
569586
path = tempdir_factory.get()

0 commit comments

Comments
 (0)