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
11 test_expect_success
'setup commits' '
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
27 git config remote.origin.receivepack "\"\$FAKE_RP_ROOT/fake-rp\""
30 test_expect_success
'detect missing branches early' '
33 test_must_fail git push origin missing &&
34 test_cmp expect rp-ran
37 test_expect_success
'detect missing sha1 expressions early' '
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' '
63 test_must_fail git push origin foo &&
64 test_cmp expect rp-ran