Merge branch 'ab/hook-tests'
Test modernization. * ab/hook-tests: hook tests: use a modern style for "pre-push" tests hook tests: test for exact "pre-push" hook input
This commit is contained in:
@ -11,7 +11,7 @@ HOOKDIR="$(git rev-parse --git-dir)/hooks"
|
|||||||
HOOK="$HOOKDIR/pre-push"
|
HOOK="$HOOKDIR/pre-push"
|
||||||
mkdir -p "$HOOKDIR"
|
mkdir -p "$HOOKDIR"
|
||||||
write_script "$HOOK" <<EOF
|
write_script "$HOOK" <<EOF
|
||||||
cat >/dev/null
|
cat >actual
|
||||||
exit 0
|
exit 0
|
||||||
EOF
|
EOF
|
||||||
|
|
||||||
@ -20,10 +20,16 @@ test_expect_success 'setup' '
|
|||||||
git init --bare repo1 &&
|
git init --bare repo1 &&
|
||||||
git remote add parent1 repo1 &&
|
git remote add parent1 repo1 &&
|
||||||
test_commit one &&
|
test_commit one &&
|
||||||
git push parent1 HEAD:foreign
|
cat >expect <<-EOF &&
|
||||||
|
HEAD $(git rev-parse HEAD) refs/heads/foreign $(test_oid zero)
|
||||||
|
EOF
|
||||||
|
|
||||||
|
test_when_finished "rm actual" &&
|
||||||
|
git push parent1 HEAD:foreign &&
|
||||||
|
test_cmp expect actual
|
||||||
'
|
'
|
||||||
write_script "$HOOK" <<EOF
|
write_script "$HOOK" <<EOF
|
||||||
cat >/dev/null
|
cat >actual
|
||||||
exit 1
|
exit 1
|
||||||
EOF
|
EOF
|
||||||
|
|
||||||
@ -32,11 +38,18 @@ export COMMIT1
|
|||||||
|
|
||||||
test_expect_success 'push with failing hook' '
|
test_expect_success 'push with failing hook' '
|
||||||
test_commit two &&
|
test_commit two &&
|
||||||
test_must_fail git push parent1 HEAD
|
cat >expect <<-EOF &&
|
||||||
|
HEAD $(git rev-parse HEAD) refs/heads/main $(test_oid zero)
|
||||||
|
EOF
|
||||||
|
|
||||||
|
test_when_finished "rm actual" &&
|
||||||
|
test_must_fail git push parent1 HEAD &&
|
||||||
|
test_cmp expect actual
|
||||||
'
|
'
|
||||||
|
|
||||||
test_expect_success '--no-verify bypasses hook' '
|
test_expect_success '--no-verify bypasses hook' '
|
||||||
git push --no-verify parent1 HEAD
|
git push --no-verify parent1 HEAD &&
|
||||||
|
test_path_is_missing actual
|
||||||
'
|
'
|
||||||
|
|
||||||
COMMIT2="$(git rev-parse HEAD)"
|
COMMIT2="$(git rev-parse HEAD)"
|
||||||
@ -48,15 +61,15 @@ echo "$2" >>actual
|
|||||||
cat >>actual
|
cat >>actual
|
||||||
EOF
|
EOF
|
||||||
|
|
||||||
cat >expected <<EOF
|
|
||||||
parent1
|
|
||||||
repo1
|
|
||||||
refs/heads/main $COMMIT2 refs/heads/foreign $COMMIT1
|
|
||||||
EOF
|
|
||||||
|
|
||||||
test_expect_success 'push with hook' '
|
test_expect_success 'push with hook' '
|
||||||
|
cat >expect <<-EOF &&
|
||||||
|
parent1
|
||||||
|
repo1
|
||||||
|
refs/heads/main $COMMIT2 refs/heads/foreign $COMMIT1
|
||||||
|
EOF
|
||||||
|
|
||||||
git push parent1 main:foreign &&
|
git push parent1 main:foreign &&
|
||||||
diff expected actual
|
test_cmp expect actual
|
||||||
'
|
'
|
||||||
|
|
||||||
test_expect_success 'add a branch' '
|
test_expect_success 'add a branch' '
|
||||||
@ -67,49 +80,48 @@ test_expect_success 'add a branch' '
|
|||||||
COMMIT3="$(git rev-parse HEAD)"
|
COMMIT3="$(git rev-parse HEAD)"
|
||||||
export COMMIT3
|
export COMMIT3
|
||||||
|
|
||||||
cat >expected <<EOF
|
|
||||||
parent1
|
|
||||||
repo1
|
|
||||||
refs/heads/other $COMMIT3 refs/heads/foreign $COMMIT2
|
|
||||||
EOF
|
|
||||||
|
|
||||||
test_expect_success 'push to default' '
|
test_expect_success 'push to default' '
|
||||||
|
cat >expect <<-EOF &&
|
||||||
|
parent1
|
||||||
|
repo1
|
||||||
|
refs/heads/other $COMMIT3 refs/heads/foreign $COMMIT2
|
||||||
|
EOF
|
||||||
git push &&
|
git push &&
|
||||||
diff expected actual
|
test_cmp expect actual
|
||||||
'
|
'
|
||||||
|
|
||||||
cat >expected <<EOF
|
|
||||||
parent1
|
|
||||||
repo1
|
|
||||||
refs/tags/one $COMMIT1 refs/tags/tag1 $ZERO_OID
|
|
||||||
HEAD~ $COMMIT2 refs/heads/prev $ZERO_OID
|
|
||||||
EOF
|
|
||||||
|
|
||||||
test_expect_success 'push non-branches' '
|
test_expect_success 'push non-branches' '
|
||||||
git push parent1 one:tag1 HEAD~:refs/heads/prev &&
|
cat >expect <<-EOF &&
|
||||||
diff expected actual
|
parent1
|
||||||
'
|
repo1
|
||||||
|
refs/tags/one $COMMIT1 refs/tags/tag1 $ZERO_OID
|
||||||
|
HEAD~ $COMMIT2 refs/heads/prev $ZERO_OID
|
||||||
|
EOF
|
||||||
|
|
||||||
cat >expected <<EOF
|
git push parent1 one:tag1 HEAD~:refs/heads/prev &&
|
||||||
parent1
|
test_cmp expect actual
|
||||||
repo1
|
'
|
||||||
(delete) $ZERO_OID refs/heads/prev $COMMIT2
|
|
||||||
EOF
|
|
||||||
|
|
||||||
test_expect_success 'push delete' '
|
test_expect_success 'push delete' '
|
||||||
|
cat >expect <<-EOF &&
|
||||||
|
parent1
|
||||||
|
repo1
|
||||||
|
(delete) $ZERO_OID refs/heads/prev $COMMIT2
|
||||||
|
EOF
|
||||||
|
|
||||||
git push parent1 :prev &&
|
git push parent1 :prev &&
|
||||||
diff expected actual
|
test_cmp expect actual
|
||||||
'
|
'
|
||||||
|
|
||||||
cat >expected <<EOF
|
|
||||||
repo1
|
|
||||||
repo1
|
|
||||||
HEAD $COMMIT3 refs/heads/other $ZERO_OID
|
|
||||||
EOF
|
|
||||||
|
|
||||||
test_expect_success 'push to URL' '
|
test_expect_success 'push to URL' '
|
||||||
|
cat >expect <<-EOF &&
|
||||||
|
repo1
|
||||||
|
repo1
|
||||||
|
HEAD $COMMIT3 refs/heads/other $ZERO_OID
|
||||||
|
EOF
|
||||||
|
|
||||||
git push repo1 HEAD &&
|
git push repo1 HEAD &&
|
||||||
diff expected actual
|
test_cmp expect actual
|
||||||
'
|
'
|
||||||
|
|
||||||
test_expect_success 'set up many-ref tests' '
|
test_expect_success 'set up many-ref tests' '
|
||||||
|
Reference in New Issue
Block a user