Git fork
at reftables-rust 141 lines 2.7 kB view raw
1#!/bin/sh 2 3test_description='check pre-push hooks' 4GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME=main 5export GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME 6 7. ./test-lib.sh 8 9test_expect_success 'setup' ' 10 test_hook pre-push <<-\EOF && 11 cat >actual 12 EOF 13 14 git config push.default upstream && 15 git init --bare repo1 && 16 git remote add parent1 repo1 && 17 test_commit one && 18 cat >expect <<-EOF && 19 HEAD $(git rev-parse HEAD) refs/heads/foreign $(test_oid zero) 20 EOF 21 22 test_when_finished "rm actual" && 23 git push parent1 HEAD:foreign && 24 test_cmp expect actual 25' 26 27COMMIT1="$(git rev-parse HEAD)" 28export COMMIT1 29 30test_expect_success 'push with failing hook' ' 31 test_hook pre-push <<-\EOF && 32 cat >actual && 33 exit 1 34 EOF 35 36 test_commit two && 37 cat >expect <<-EOF && 38 HEAD $(git rev-parse HEAD) refs/heads/main $(test_oid zero) 39 EOF 40 41 test_when_finished "rm actual" && 42 test_must_fail git push parent1 HEAD && 43 test_cmp expect actual 44' 45 46test_expect_success '--no-verify bypasses hook' ' 47 git push --no-verify parent1 HEAD && 48 test_path_is_missing actual 49' 50 51COMMIT2="$(git rev-parse HEAD)" 52export COMMIT2 53 54test_expect_success 'push with hook' ' 55 test_hook --setup pre-push <<-\EOF && 56 echo "$1" >actual 57 echo "$2" >>actual 58 cat >>actual 59 EOF 60 61 cat >expect <<-EOF && 62 parent1 63 repo1 64 refs/heads/main $COMMIT2 refs/heads/foreign $COMMIT1 65 EOF 66 67 git push parent1 main:foreign && 68 test_cmp expect actual 69' 70 71test_expect_success 'add a branch' ' 72 git checkout -b other parent1/foreign && 73 test_commit three 74' 75 76COMMIT3="$(git rev-parse HEAD)" 77export COMMIT3 78 79test_expect_success 'push to default' ' 80 cat >expect <<-EOF && 81 parent1 82 repo1 83 refs/heads/other $COMMIT3 refs/heads/foreign $COMMIT2 84 EOF 85 git push && 86 test_cmp expect actual 87' 88 89test_expect_success 'push non-branches' ' 90 cat >expect <<-EOF && 91 parent1 92 repo1 93 refs/tags/one $COMMIT1 refs/tags/tag1 $ZERO_OID 94 HEAD~ $COMMIT2 refs/heads/prev $ZERO_OID 95 EOF 96 97 git push parent1 one:tag1 HEAD~:refs/heads/prev && 98 test_cmp expect actual 99' 100 101test_expect_success 'push delete' ' 102 cat >expect <<-EOF && 103 parent1 104 repo1 105 (delete) $ZERO_OID refs/heads/prev $COMMIT2 106 EOF 107 108 git push parent1 :prev && 109 test_cmp expect actual 110' 111 112test_expect_success 'push to URL' ' 113 cat >expect <<-EOF && 114 repo1 115 repo1 116 HEAD $COMMIT3 refs/heads/other $ZERO_OID 117 EOF 118 119 git push repo1 HEAD && 120 test_cmp expect actual 121' 122 123test_expect_success 'set up many-ref tests' ' 124 { 125 nr=1000 && 126 while test $nr -lt 2000 127 do 128 nr=$(( $nr + 1 )) && 129 echo "create refs/heads/b/$nr $COMMIT3" || return 1 130 done 131 } | git update-ref --stdin 132' 133 134test_expect_success 'sigpipe does not cause pre-push hook failure' ' 135 test_hook --clobber pre-push <<-\EOF && 136 exit 0 137 EOF 138 git push parent1 "refs/heads/b/*:refs/heads/b/*" 139' 140 141test_done