Start deprecating "git-command" in favor of "git command"
[git.git] / t / t5516-fetch-push.sh
blobc0fa2ba404a7772af07d8546a51b05bd9b17ec2c
1 #!/bin/sh
3 test_description='fetching and pushing, with or without wildcard'
5 . ./test-lib.sh
7 D=`pwd`
9 mk_empty () {
10 rm -fr testrepo &&
11 mkdir testrepo &&
13 cd testrepo &&
14 git init
18 mk_test () {
19 mk_empty &&
21 for ref in "$@"
23 git push testrepo $the_first_commit:refs/$ref || {
24 echo "Oops, push refs/$ref failure"
25 exit 1
27 done &&
28 cd testrepo &&
29 for ref in "$@"
31 r=$(git show-ref -s --verify refs/$ref) &&
32 test "z$r" = "z$the_first_commit" || {
33 echo "Oops, refs/$ref is wrong"
34 exit 1
36 done &&
37 git fsck --full
41 check_push_result () {
43 cd testrepo &&
44 it="$1" &&
45 shift
46 for ref in "$@"
48 r=$(git show-ref -s --verify refs/$ref) &&
49 test "z$r" = "z$it" || {
50 echo "Oops, refs/$ref is wrong"
51 exit 1
53 done &&
54 git fsck --full
58 test_expect_success setup '
60 : >path1 &&
61 git add path1 &&
62 test_tick &&
63 git commit -a -m repo &&
64 the_first_commit=$(git show-ref -s --verify refs/heads/master) &&
66 : >path2 &&
67 git add path2 &&
68 test_tick &&
69 git commit -a -m second &&
70 the_commit=$(git show-ref -s --verify refs/heads/master)
74 test_expect_success 'fetch without wildcard' '
75 mk_empty &&
77 cd testrepo &&
78 git fetch .. refs/heads/master:refs/remotes/origin/master &&
80 r=$(git show-ref -s --verify refs/remotes/origin/master) &&
81 test "z$r" = "z$the_commit" &&
83 test 1 = $(git for-each-ref refs/remotes/origin | wc -l)
87 test_expect_success 'fetch with wildcard' '
88 mk_empty &&
90 cd testrepo &&
91 git config remote.up.url .. &&
92 git config remote.up.fetch "refs/heads/*:refs/remotes/origin/*" &&
93 git fetch up &&
95 r=$(git show-ref -s --verify refs/remotes/origin/master) &&
96 test "z$r" = "z$the_commit" &&
98 test 1 = $(git for-each-ref refs/remotes/origin | wc -l)
102 test_expect_success 'push without wildcard' '
103 mk_empty &&
105 git push testrepo refs/heads/master:refs/remotes/origin/master &&
107 cd testrepo &&
108 r=$(git show-ref -s --verify refs/remotes/origin/master) &&
109 test "z$r" = "z$the_commit" &&
111 test 1 = $(git for-each-ref refs/remotes/origin | wc -l)
115 test_expect_success 'push with wildcard' '
116 mk_empty &&
118 git push testrepo "refs/heads/*:refs/remotes/origin/*" &&
120 cd testrepo &&
121 r=$(git show-ref -s --verify refs/remotes/origin/master) &&
122 test "z$r" = "z$the_commit" &&
124 test 1 = $(git for-each-ref refs/remotes/origin | wc -l)
128 test_expect_success 'push with matching heads' '
130 mk_test heads/master &&
131 git push testrepo &&
132 check_push_result $the_commit heads/master
136 test_expect_success 'push with no ambiguity (1)' '
138 mk_test heads/master &&
139 git push testrepo master:master &&
140 check_push_result $the_commit heads/master
144 test_expect_success 'push with no ambiguity (2)' '
146 mk_test remotes/origin/master &&
147 git push testrepo master:master &&
148 check_push_result $the_commit remotes/origin/master
152 test_expect_success 'push with weak ambiguity (1)' '
154 mk_test heads/master remotes/origin/master &&
155 git push testrepo master:master &&
156 check_push_result $the_commit heads/master &&
157 check_push_result $the_first_commit remotes/origin/master
161 test_expect_success 'push with weak ambiguity (2)' '
163 mk_test heads/master remotes/origin/master remotes/another/master &&
164 git push testrepo master:master &&
165 check_push_result $the_commit heads/master &&
166 check_push_result $the_first_commit remotes/origin/master remotes/another/master
170 test_expect_success 'push with ambiguity (1)' '
172 mk_test remotes/origin/master remotes/frotz/master &&
173 if git push testrepo master:master
174 then
175 echo "Oops, should have failed"
176 false
177 else
178 check_push_result $the_first_commit remotes/origin/master remotes/frotz/master
182 test_expect_success 'push with ambiguity (2)' '
184 mk_test heads/frotz tags/frotz &&
185 if git push testrepo master:frotz
186 then
187 echo "Oops, should have failed"
188 false
189 else
190 check_push_result $the_first_commit heads/frotz tags/frotz
195 test_expect_success 'push with colon-less refspec (1)' '
197 mk_test heads/frotz tags/frotz &&
198 git branch -f frotz master &&
199 git push testrepo frotz &&
200 check_push_result $the_commit heads/frotz &&
201 check_push_result $the_first_commit tags/frotz
205 test_expect_success 'push with colon-less refspec (2)' '
207 mk_test heads/frotz tags/frotz &&
208 if git show-ref --verify -q refs/heads/frotz
209 then
210 git branch -D frotz
211 fi &&
212 git tag -f frotz &&
213 git push testrepo frotz &&
214 check_push_result $the_commit tags/frotz &&
215 check_push_result $the_first_commit heads/frotz
219 test_expect_success 'push with colon-less refspec (3)' '
221 mk_test &&
222 if git show-ref --verify -q refs/tags/frotz
223 then
224 git tag -d frotz
225 fi &&
226 git branch -f frotz master &&
227 git push testrepo frotz &&
228 check_push_result $the_commit heads/frotz &&
229 test 1 = $( cd testrepo && git show-ref | wc -l )
232 test_expect_success 'push with colon-less refspec (4)' '
234 mk_test &&
235 if git show-ref --verify -q refs/heads/frotz
236 then
237 git branch -D frotz
238 fi &&
239 git tag -f frotz &&
240 git push testrepo frotz &&
241 check_push_result $the_commit tags/frotz &&
242 test 1 = $( cd testrepo && git show-ref | wc -l )
246 test_done