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