Merge branch 'ja/doc-synopsis-markup'
[git/gitster.git] / t / t5529-push-errors.sh
blob17d72578926acc0eb3823712deb79fa72aa470bd
1 #!/bin/sh
3 test_description='detect some push errors early (before contacting remote)'
5 GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME=main
6 export GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME
8 TEST_PASSES_SANITIZE_LEAK=true
9 . ./test-lib.sh
11 test_expect_success 'setup commits' '
12 test_commit one
15 test_expect_success 'setup remote' '
16 git init --bare remote.git &&
17 git remote add origin remote.git
20 test_expect_success 'setup fake receive-pack' '
21 FAKE_RP_ROOT=$(pwd) &&
22 export FAKE_RP_ROOT &&
23 write_script fake-rp <<-\EOF &&
24 echo yes >"$FAKE_RP_ROOT"/rp-ran
25 exit 1
26 EOF
27 git config remote.origin.receivepack "\"\$FAKE_RP_ROOT/fake-rp\""
30 test_expect_success 'detect missing branches early' '
31 echo no >rp-ran &&
32 echo no >expect &&
33 test_must_fail git push origin missing &&
34 test_cmp expect rp-ran
37 test_expect_success 'detect missing sha1 expressions early' '
38 echo no >rp-ran &&
39 echo no >expect &&
40 test_must_fail git push origin main~2:main &&
41 test_cmp expect rp-ran
44 # We use an existing local_ref, since it follows a different flow in
45 # 'builtin/push.c:set_refspecs()' and we want to test that regression.
46 test_expect_success 'detect empty remote with existing local ref' '
47 test_must_fail git push "" main 2> stderr &&
48 grep "fatal: bad repository ${SQ}${SQ}" stderr
51 # While similar to the previous test, here we want to ensure that
52 # even targeted refspecs are handled.
53 test_expect_success 'detect empty remote with targeted refspec' '
54 test_must_fail git push "" HEAD:refs/heads/main 2> stderr &&
55 grep "fatal: bad repository ${SQ}${SQ}" stderr
58 test_expect_success 'detect ambiguous refs early' '
59 git branch foo &&
60 git tag foo &&
61 echo no >rp-ran &&
62 echo no >expect &&
63 test_must_fail git push origin foo &&
64 test_cmp expect rp-ran
67 test_done