Merge branch 'maint-1.5.4' into maint
[git.git] / t / t5516-fetch-push.sh
blobf93a100f8732dcde2a8e52fc24ab5d54d4890b23
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 &&
15 mv .git/hooks .git/hooks-disabled
19 mk_test () {
20 mk_empty &&
22 for ref in "$@"
24 git push testrepo $the_first_commit:refs/$ref || {
25 echo "Oops, push refs/$ref failure"
26 exit 1
28 done &&
29 cd testrepo &&
30 for ref in "$@"
32 r=$(git show-ref -s --verify refs/$ref) &&
33 test "z$r" = "z$the_first_commit" || {
34 echo "Oops, refs/$ref is wrong"
35 exit 1
37 done &&
38 git fsck --full
42 check_push_result () {
44 cd testrepo &&
45 it="$1" &&
46 shift
47 for ref in "$@"
49 r=$(git show-ref -s --verify refs/$ref) &&
50 test "z$r" = "z$it" || {
51 echo "Oops, refs/$ref is wrong"
52 exit 1
54 done &&
55 git fsck --full
59 test_expect_success setup '
61 : >path1 &&
62 git add path1 &&
63 test_tick &&
64 git commit -a -m repo &&
65 the_first_commit=$(git show-ref -s --verify refs/heads/master) &&
67 : >path2 &&
68 git add path2 &&
69 test_tick &&
70 git commit -a -m second &&
71 the_commit=$(git show-ref -s --verify refs/heads/master)
75 test_expect_success 'fetch without wildcard' '
76 mk_empty &&
78 cd testrepo &&
79 git fetch .. refs/heads/master:refs/remotes/origin/master &&
81 r=$(git show-ref -s --verify refs/remotes/origin/master) &&
82 test "z$r" = "z$the_commit" &&
84 test 1 = $(git for-each-ref refs/remotes/origin | wc -l)
88 test_expect_success 'fetch with wildcard' '
89 mk_empty &&
91 cd testrepo &&
92 git config remote.up.url .. &&
93 git config remote.up.fetch "refs/heads/*:refs/remotes/origin/*" &&
94 git fetch up &&
96 r=$(git show-ref -s --verify refs/remotes/origin/master) &&
97 test "z$r" = "z$the_commit" &&
99 test 1 = $(git for-each-ref refs/remotes/origin | wc -l)
103 test_expect_success 'fetch with insteadOf' '
104 mk_empty &&
106 TRASH=$(pwd)/ &&
107 cd testrepo &&
108 git config url.$TRASH.insteadOf trash/
109 git config remote.up.url trash/. &&
110 git config remote.up.fetch "refs/heads/*:refs/remotes/origin/*" &&
111 git fetch up &&
113 r=$(git show-ref -s --verify refs/remotes/origin/master) &&
114 test "z$r" = "z$the_commit" &&
116 test 1 = $(git for-each-ref refs/remotes/origin | wc -l)
120 test_expect_success 'push without wildcard' '
121 mk_empty &&
123 git push testrepo refs/heads/master:refs/remotes/origin/master &&
125 cd testrepo &&
126 r=$(git show-ref -s --verify refs/remotes/origin/master) &&
127 test "z$r" = "z$the_commit" &&
129 test 1 = $(git for-each-ref refs/remotes/origin | wc -l)
133 test_expect_success 'push with wildcard' '
134 mk_empty &&
136 git push testrepo "refs/heads/*:refs/remotes/origin/*" &&
138 cd testrepo &&
139 r=$(git show-ref -s --verify refs/remotes/origin/master) &&
140 test "z$r" = "z$the_commit" &&
142 test 1 = $(git for-each-ref refs/remotes/origin | wc -l)
146 test_expect_success 'push with insteadOf' '
147 mk_empty &&
148 TRASH=$(pwd)/ &&
149 git config url.$TRASH.insteadOf trash/ &&
150 git push trash/testrepo refs/heads/master:refs/remotes/origin/master &&
152 cd testrepo &&
153 r=$(git show-ref -s --verify refs/remotes/origin/master) &&
154 test "z$r" = "z$the_commit" &&
156 test 1 = $(git for-each-ref refs/remotes/origin | wc -l)
160 test_expect_success 'push with matching heads' '
162 mk_test heads/master &&
163 git push testrepo &&
164 check_push_result $the_commit heads/master
168 test_expect_success 'push with no ambiguity (1)' '
170 mk_test heads/master &&
171 git push testrepo master:master &&
172 check_push_result $the_commit heads/master
176 test_expect_success 'push with no ambiguity (2)' '
178 mk_test remotes/origin/master &&
179 git push testrepo master:origin/master &&
180 check_push_result $the_commit remotes/origin/master
184 test_expect_success 'push with colon-less refspec, no ambiguity' '
186 mk_test heads/master heads/t/master &&
187 git branch -f t/master master &&
188 git push testrepo master &&
189 check_push_result $the_commit heads/master &&
190 check_push_result $the_first_commit heads/t/master
194 test_expect_success 'push with weak ambiguity (1)' '
196 mk_test heads/master remotes/origin/master &&
197 git push testrepo master:master &&
198 check_push_result $the_commit heads/master &&
199 check_push_result $the_first_commit remotes/origin/master
203 test_expect_success 'push with weak ambiguity (2)' '
205 mk_test heads/master remotes/origin/master remotes/another/master &&
206 git push testrepo master:master &&
207 check_push_result $the_commit heads/master &&
208 check_push_result $the_first_commit remotes/origin/master remotes/another/master
212 test_expect_success 'push with ambiguity' '
214 mk_test heads/frotz tags/frotz &&
215 if git push testrepo master:frotz
216 then
217 echo "Oops, should have failed"
218 false
219 else
220 check_push_result $the_first_commit heads/frotz tags/frotz
225 test_expect_success 'push with colon-less refspec (1)' '
227 mk_test heads/frotz tags/frotz &&
228 git branch -f frotz master &&
229 git push testrepo frotz &&
230 check_push_result $the_commit heads/frotz &&
231 check_push_result $the_first_commit tags/frotz
235 test_expect_success 'push with colon-less refspec (2)' '
237 mk_test heads/frotz tags/frotz &&
238 if git show-ref --verify -q refs/heads/frotz
239 then
240 git branch -D frotz
241 fi &&
242 git tag -f frotz &&
243 git push testrepo frotz &&
244 check_push_result $the_commit tags/frotz &&
245 check_push_result $the_first_commit heads/frotz
249 test_expect_success 'push with colon-less refspec (3)' '
251 mk_test &&
252 if git show-ref --verify -q refs/tags/frotz
253 then
254 git tag -d frotz
255 fi &&
256 git branch -f frotz master &&
257 git push testrepo frotz &&
258 check_push_result $the_commit heads/frotz &&
259 test 1 = $( cd testrepo && git show-ref | wc -l )
262 test_expect_success 'push with colon-less refspec (4)' '
264 mk_test &&
265 if git show-ref --verify -q refs/heads/frotz
266 then
267 git branch -D frotz
268 fi &&
269 git tag -f frotz &&
270 git push testrepo frotz &&
271 check_push_result $the_commit tags/frotz &&
272 test 1 = $( cd testrepo && git show-ref | wc -l )
276 test_expect_success 'push with HEAD' '
278 mk_test heads/master &&
279 git checkout master &&
280 git push testrepo HEAD &&
281 check_push_result $the_commit heads/master
285 test_expect_success 'push with HEAD nonexisting at remote' '
287 mk_test heads/master &&
288 git checkout -b local master &&
289 git push testrepo HEAD &&
290 check_push_result $the_commit heads/local
293 test_expect_success 'push with +HEAD' '
295 mk_test heads/master &&
296 git checkout master &&
297 git branch -D local &&
298 git checkout -b local &&
299 git push testrepo master local &&
300 check_push_result $the_commit heads/master &&
301 check_push_result $the_commit heads/local &&
303 # Without force rewinding should fail
304 git reset --hard HEAD^ &&
305 ! git push testrepo HEAD &&
306 check_push_result $the_commit heads/local &&
308 # With force rewinding should succeed
309 git push testrepo +HEAD &&
310 check_push_result $the_first_commit heads/local
314 test_expect_success 'push with config remote.*.push = HEAD' '
316 mk_test heads/local &&
317 git checkout master &&
318 git branch -f local $the_commit &&
320 cd testrepo &&
321 git checkout local &&
322 git reset --hard $the_first_commit
323 ) &&
324 git config remote.there.url testrepo &&
325 git config remote.there.push HEAD &&
326 git config branch.master.remote there &&
327 git push &&
328 check_push_result $the_commit heads/master &&
329 check_push_result $the_first_commit heads/local
332 # clean up the cruft left with the previous one
333 git config --remove-section remote.there
334 git config --remove-section branch.master
336 test_expect_success 'push with dry-run' '
338 mk_test heads/master &&
339 (cd testrepo &&
340 old_commit=$(git show-ref -s --verify refs/heads/master)) &&
341 git push --dry-run testrepo &&
342 check_push_result $old_commit heads/master
345 test_expect_success 'push updates local refs' '
347 rm -rf parent child &&
348 mkdir parent &&
349 (cd parent && git init &&
350 echo one >foo && git add foo && git commit -m one) &&
351 git clone parent child &&
352 (cd child &&
353 echo two >foo && git commit -a -m two &&
354 git push &&
355 test $(git rev-parse master) = $(git rev-parse remotes/origin/master))
359 test_expect_success 'push does not update local refs on failure' '
361 rm -rf parent child &&
362 mkdir parent &&
363 (cd parent && git init &&
364 echo one >foo && git add foo && git commit -m one &&
365 echo exit 1 >.git/hooks/pre-receive &&
366 chmod +x .git/hooks/pre-receive) &&
367 git clone parent child &&
368 (cd child &&
369 echo two >foo && git commit -a -m two &&
370 ! git push &&
371 test $(git rev-parse master) != \
372 $(git rev-parse remotes/origin/master))
376 test_expect_success 'allow deleting an invalid remote ref' '
378 pwd &&
379 rm -f testrepo/.git/objects/??/* &&
380 git push testrepo :refs/heads/master &&
381 (cd testrepo && ! git rev-parse --verify refs/heads/master)
385 test_done