]>
Commit | Line | Data |
---|---|---|
bcdb34f7 JH |
1 | #!/bin/sh |
2 | ||
3 | test_description='fetching and pushing, with or without wildcard' | |
4 | ||
5 | . ./test-lib.sh | |
6 | ||
7 | D=`pwd` | |
8 | ||
9 | mk_empty () { | |
10 | rm -fr testrepo && | |
11 | mkdir testrepo && | |
12 | ( | |
13 | cd testrepo && | |
586e4ce2 | 14 | git init && |
acd2a45b | 15 | git config receive.denyCurrentBranch warn && |
586e4ce2 | 16 | mv .git/hooks .git/hooks-disabled |
bcdb34f7 JH |
17 | ) |
18 | } | |
19 | ||
6125796f JH |
20 | mk_test () { |
21 | mk_empty && | |
22 | ( | |
23 | for ref in "$@" | |
24 | do | |
25 | git push testrepo $the_first_commit:refs/$ref || { | |
26 | echo "Oops, push refs/$ref failure" | |
27 | exit 1 | |
28 | } | |
29 | done && | |
30 | cd testrepo && | |
31 | for ref in "$@" | |
32 | do | |
33 | r=$(git show-ref -s --verify refs/$ref) && | |
34 | test "z$r" = "z$the_first_commit" || { | |
35 | echo "Oops, refs/$ref is wrong" | |
36 | exit 1 | |
37 | } | |
38 | done && | |
39 | git fsck --full | |
40 | ) | |
41 | } | |
42 | ||
160b81ed PYH |
43 | mk_test_with_hooks() { |
44 | mk_test "$@" && | |
45 | ( | |
46 | cd testrepo && | |
47 | mkdir .git/hooks && | |
48 | cd .git/hooks && | |
49 | ||
50 | cat >pre-receive <<-'EOF' && | |
51 | #!/bin/sh | |
52 | cat - >>pre-receive.actual | |
53 | EOF | |
54 | ||
55 | cat >update <<-'EOF' && | |
56 | #!/bin/sh | |
57 | printf "%s %s %s\n" "$@" >>update.actual | |
58 | EOF | |
59 | ||
60 | cat >post-receive <<-'EOF' && | |
61 | #!/bin/sh | |
62 | cat - >>post-receive.actual | |
63 | EOF | |
64 | ||
65 | cat >post-update <<-'EOF' && | |
66 | #!/bin/sh | |
67 | for ref in "$@" | |
68 | do | |
69 | printf "%s\n" "$ref" >>post-update.actual | |
70 | done | |
71 | EOF | |
72 | ||
73 | chmod +x pre-receive update post-receive post-update | |
74 | ) | |
75 | } | |
76 | ||
b2dc968e JK |
77 | mk_child() { |
78 | rm -rf "$1" && | |
79 | git clone testrepo "$1" | |
80 | } | |
81 | ||
6125796f JH |
82 | check_push_result () { |
83 | ( | |
84 | cd testrepo && | |
85 | it="$1" && | |
86 | shift | |
87 | for ref in "$@" | |
88 | do | |
89 | r=$(git show-ref -s --verify refs/$ref) && | |
90 | test "z$r" = "z$it" || { | |
91 | echo "Oops, refs/$ref is wrong" | |
92 | exit 1 | |
93 | } | |
94 | done && | |
95 | git fsck --full | |
96 | ) | |
97 | } | |
98 | ||
bcdb34f7 JH |
99 | test_expect_success setup ' |
100 | ||
d4785cd1 | 101 | >path1 && |
bcdb34f7 JH |
102 | git add path1 && |
103 | test_tick && | |
104 | git commit -a -m repo && | |
6125796f JH |
105 | the_first_commit=$(git show-ref -s --verify refs/heads/master) && |
106 | ||
d4785cd1 | 107 | >path2 && |
6125796f JH |
108 | git add path2 && |
109 | test_tick && | |
110 | git commit -a -m second && | |
bcdb34f7 JH |
111 | the_commit=$(git show-ref -s --verify refs/heads/master) |
112 | ||
113 | ' | |
114 | ||
115 | test_expect_success 'fetch without wildcard' ' | |
116 | mk_empty && | |
117 | ( | |
118 | cd testrepo && | |
119 | git fetch .. refs/heads/master:refs/remotes/origin/master && | |
120 | ||
121 | r=$(git show-ref -s --verify refs/remotes/origin/master) && | |
122 | test "z$r" = "z$the_commit" && | |
123 | ||
124 | test 1 = $(git for-each-ref refs/remotes/origin | wc -l) | |
125 | ) | |
126 | ' | |
127 | ||
128 | test_expect_success 'fetch with wildcard' ' | |
129 | mk_empty && | |
130 | ( | |
131 | cd testrepo && | |
132 | git config remote.up.url .. && | |
133 | git config remote.up.fetch "refs/heads/*:refs/remotes/origin/*" && | |
134 | git fetch up && | |
135 | ||
136 | r=$(git show-ref -s --verify refs/remotes/origin/master) && | |
137 | test "z$r" = "z$the_commit" && | |
138 | ||
139 | test 1 = $(git for-each-ref refs/remotes/origin | wc -l) | |
140 | ) | |
141 | ' | |
142 | ||
55029ae4 DB |
143 | test_expect_success 'fetch with insteadOf' ' |
144 | mk_empty && | |
145 | ( | |
60e3aba9 | 146 | TRASH=$(pwd)/ && |
55029ae4 | 147 | cd testrepo && |
f69e836f | 148 | git config "url.$TRASH.insteadOf" trash/ && |
55029ae4 DB |
149 | git config remote.up.url trash/. && |
150 | git config remote.up.fetch "refs/heads/*:refs/remotes/origin/*" && | |
151 | git fetch up && | |
152 | ||
153 | r=$(git show-ref -s --verify refs/remotes/origin/master) && | |
154 | test "z$r" = "z$the_commit" && | |
155 | ||
156 | test 1 = $(git for-each-ref refs/remotes/origin | wc -l) | |
157 | ) | |
158 | ' | |
159 | ||
1c2eafb8 JT |
160 | test_expect_success 'fetch with pushInsteadOf (should not rewrite)' ' |
161 | mk_empty && | |
162 | ( | |
163 | TRASH=$(pwd)/ && | |
164 | cd testrepo && | |
165 | git config "url.trash/.pushInsteadOf" "$TRASH" && | |
166 | git config remote.up.url "$TRASH." && | |
167 | git config remote.up.fetch "refs/heads/*:refs/remotes/origin/*" && | |
168 | git fetch up && | |
169 | ||
170 | r=$(git show-ref -s --verify refs/remotes/origin/master) && | |
171 | test "z$r" = "z$the_commit" && | |
172 | ||
173 | test 1 = $(git for-each-ref refs/remotes/origin | wc -l) | |
174 | ) | |
175 | ' | |
176 | ||
bcdb34f7 JH |
177 | test_expect_success 'push without wildcard' ' |
178 | mk_empty && | |
179 | ||
180 | git push testrepo refs/heads/master:refs/remotes/origin/master && | |
181 | ( | |
182 | cd testrepo && | |
183 | r=$(git show-ref -s --verify refs/remotes/origin/master) && | |
184 | test "z$r" = "z$the_commit" && | |
185 | ||
186 | test 1 = $(git for-each-ref refs/remotes/origin | wc -l) | |
187 | ) | |
188 | ' | |
189 | ||
190 | test_expect_success 'push with wildcard' ' | |
191 | mk_empty && | |
192 | ||
193 | git push testrepo "refs/heads/*:refs/remotes/origin/*" && | |
194 | ( | |
195 | cd testrepo && | |
196 | r=$(git show-ref -s --verify refs/remotes/origin/master) && | |
197 | test "z$r" = "z$the_commit" && | |
198 | ||
199 | test 1 = $(git for-each-ref refs/remotes/origin | wc -l) | |
200 | ) | |
201 | ' | |
202 | ||
55029ae4 DB |
203 | test_expect_success 'push with insteadOf' ' |
204 | mk_empty && | |
f69e836f | 205 | TRASH="$(pwd)/" && |
70ca472f | 206 | git config "url.$TRASH.insteadOf" trash/ && |
55029ae4 DB |
207 | git push trash/testrepo refs/heads/master:refs/remotes/origin/master && |
208 | ( | |
209 | cd testrepo && | |
210 | r=$(git show-ref -s --verify refs/remotes/origin/master) && | |
211 | test "z$r" = "z$the_commit" && | |
212 | ||
213 | test 1 = $(git for-each-ref refs/remotes/origin | wc -l) | |
214 | ) | |
215 | ' | |
216 | ||
1c2eafb8 JT |
217 | test_expect_success 'push with pushInsteadOf' ' |
218 | mk_empty && | |
219 | TRASH="$(pwd)/" && | |
220 | git config "url.$TRASH.pushInsteadOf" trash/ && | |
221 | git push trash/testrepo refs/heads/master:refs/remotes/origin/master && | |
222 | ( | |
223 | cd testrepo && | |
224 | r=$(git show-ref -s --verify refs/remotes/origin/master) && | |
225 | test "z$r" = "z$the_commit" && | |
226 | ||
227 | test 1 = $(git for-each-ref refs/remotes/origin | wc -l) | |
228 | ) | |
229 | ' | |
230 | ||
231 | test_expect_success 'push with pushInsteadOf and explicit pushurl (pushInsteadOf should not rewrite)' ' | |
232 | mk_empty && | |
233 | TRASH="$(pwd)/" && | |
234 | git config "url.trash2/.pushInsteadOf" trash/ && | |
235 | git config remote.r.url trash/wrong && | |
236 | git config remote.r.pushurl "$TRASH/testrepo" && | |
237 | git push r refs/heads/master:refs/remotes/origin/master && | |
238 | ( | |
239 | cd testrepo && | |
240 | r=$(git show-ref -s --verify refs/remotes/origin/master) && | |
241 | test "z$r" = "z$the_commit" && | |
242 | ||
243 | test 1 = $(git for-each-ref refs/remotes/origin | wc -l) | |
244 | ) | |
245 | ' | |
246 | ||
6125796f JH |
247 | test_expect_success 'push with matching heads' ' |
248 | ||
249 | mk_test heads/master && | |
250 | git push testrepo && | |
251 | check_push_result $the_commit heads/master | |
252 | ||
253 | ' | |
254 | ||
a83619d6 PB |
255 | test_expect_success 'push with matching heads on the command line' ' |
256 | ||
257 | mk_test heads/master && | |
258 | git push testrepo : && | |
259 | check_push_result $the_commit heads/master | |
260 | ||
261 | ' | |
262 | ||
263 | test_expect_success 'failed (non-fast-forward) push with matching heads' ' | |
264 | ||
265 | mk_test heads/master && | |
266 | git push testrepo : && | |
267 | git commit --amend -massaged && | |
d492b31c | 268 | test_must_fail git push testrepo && |
a83619d6 PB |
269 | check_push_result $the_commit heads/master && |
270 | git reset --hard $the_commit | |
271 | ||
272 | ' | |
273 | ||
274 | test_expect_success 'push --force with matching heads' ' | |
275 | ||
276 | mk_test heads/master && | |
277 | git push testrepo : && | |
278 | git commit --amend -massaged && | |
279 | git push --force testrepo && | |
280 | ! check_push_result $the_commit heads/master && | |
281 | git reset --hard $the_commit | |
282 | ||
283 | ' | |
284 | ||
285 | test_expect_success 'push with matching heads and forced update' ' | |
286 | ||
287 | mk_test heads/master && | |
288 | git push testrepo : && | |
289 | git commit --amend -massaged && | |
290 | git push testrepo +: && | |
291 | ! check_push_result $the_commit heads/master && | |
292 | git reset --hard $the_commit | |
293 | ||
294 | ' | |
295 | ||
6125796f JH |
296 | test_expect_success 'push with no ambiguity (1)' ' |
297 | ||
298 | mk_test heads/master && | |
299 | git push testrepo master:master && | |
300 | check_push_result $the_commit heads/master | |
301 | ||
302 | ' | |
303 | ||
304 | test_expect_success 'push with no ambiguity (2)' ' | |
305 | ||
306 | mk_test remotes/origin/master && | |
ae36bdcf | 307 | git push testrepo master:origin/master && |
6125796f JH |
308 | check_push_result $the_commit remotes/origin/master |
309 | ||
310 | ' | |
311 | ||
ae36bdcf SP |
312 | test_expect_success 'push with colon-less refspec, no ambiguity' ' |
313 | ||
314 | mk_test heads/master heads/t/master && | |
315 | git branch -f t/master master && | |
316 | git push testrepo master && | |
317 | check_push_result $the_commit heads/master && | |
318 | check_push_result $the_first_commit heads/t/master | |
319 | ||
320 | ' | |
321 | ||
6125796f JH |
322 | test_expect_success 'push with weak ambiguity (1)' ' |
323 | ||
324 | mk_test heads/master remotes/origin/master && | |
325 | git push testrepo master:master && | |
326 | check_push_result $the_commit heads/master && | |
327 | check_push_result $the_first_commit remotes/origin/master | |
328 | ||
329 | ' | |
330 | ||
331 | test_expect_success 'push with weak ambiguity (2)' ' | |
332 | ||
333 | mk_test heads/master remotes/origin/master remotes/another/master && | |
334 | git push testrepo master:master && | |
335 | check_push_result $the_commit heads/master && | |
336 | check_push_result $the_first_commit remotes/origin/master remotes/another/master | |
337 | ||
338 | ' | |
339 | ||
3ef6a1fe | 340 | test_expect_success 'push with ambiguity' ' |
6125796f JH |
341 | |
342 | mk_test heads/frotz tags/frotz && | |
343 | if git push testrepo master:frotz | |
344 | then | |
345 | echo "Oops, should have failed" | |
346 | false | |
347 | else | |
348 | check_push_result $the_first_commit heads/frotz tags/frotz | |
349 | fi | |
1ed10b88 JH |
350 | |
351 | ' | |
352 | ||
353 | test_expect_success 'push with colon-less refspec (1)' ' | |
354 | ||
355 | mk_test heads/frotz tags/frotz && | |
356 | git branch -f frotz master && | |
357 | git push testrepo frotz && | |
358 | check_push_result $the_commit heads/frotz && | |
359 | check_push_result $the_first_commit tags/frotz | |
360 | ||
361 | ' | |
362 | ||
363 | test_expect_success 'push with colon-less refspec (2)' ' | |
364 | ||
365 | mk_test heads/frotz tags/frotz && | |
366 | if git show-ref --verify -q refs/heads/frotz | |
367 | then | |
368 | git branch -D frotz | |
369 | fi && | |
370 | git tag -f frotz && | |
dbfeddb1 | 371 | git push -f testrepo frotz && |
1ed10b88 JH |
372 | check_push_result $the_commit tags/frotz && |
373 | check_push_result $the_first_commit heads/frotz | |
374 | ||
375 | ' | |
376 | ||
377 | test_expect_success 'push with colon-less refspec (3)' ' | |
378 | ||
379 | mk_test && | |
380 | if git show-ref --verify -q refs/tags/frotz | |
381 | then | |
382 | git tag -d frotz | |
383 | fi && | |
384 | git branch -f frotz master && | |
385 | git push testrepo frotz && | |
386 | check_push_result $the_commit heads/frotz && | |
9a3c6f7b | 387 | test 1 = $( cd testrepo && git show-ref | wc -l ) |
1ed10b88 JH |
388 | ' |
389 | ||
390 | test_expect_success 'push with colon-less refspec (4)' ' | |
391 | ||
392 | mk_test && | |
393 | if git show-ref --verify -q refs/heads/frotz | |
394 | then | |
395 | git branch -D frotz | |
396 | fi && | |
397 | git tag -f frotz && | |
398 | git push testrepo frotz && | |
399 | check_push_result $the_commit tags/frotz && | |
9a3c6f7b | 400 | test 1 = $( cd testrepo && git show-ref | wc -l ) |
1ed10b88 | 401 | |
6125796f JH |
402 | ' |
403 | ||
7be8b3ba | 404 | test_expect_success 'push head with non-existent, incomplete dest' ' |
f8aae120 JK |
405 | |
406 | mk_test && | |
407 | git push testrepo master:branch && | |
408 | check_push_result $the_commit heads/branch | |
409 | ||
410 | ' | |
411 | ||
7be8b3ba | 412 | test_expect_success 'push tag with non-existent, incomplete dest' ' |
f8aae120 JK |
413 | |
414 | mk_test && | |
415 | git tag -f v1.0 && | |
416 | git push testrepo v1.0:tag && | |
417 | check_push_result $the_commit tags/tag | |
418 | ||
419 | ' | |
420 | ||
7be8b3ba | 421 | test_expect_success 'push sha1 with non-existent, incomplete dest' ' |
f8aae120 JK |
422 | |
423 | mk_test && | |
424 | test_must_fail git push testrepo `git rev-parse master`:foo | |
425 | ||
426 | ' | |
427 | ||
7be8b3ba | 428 | test_expect_success 'push ref expression with non-existent, incomplete dest' ' |
f8aae120 JK |
429 | |
430 | mk_test && | |
431 | test_must_fail git push testrepo master^:branch | |
432 | ||
433 | ' | |
434 | ||
47d996a2 SP |
435 | test_expect_success 'push with HEAD' ' |
436 | ||
437 | mk_test heads/master && | |
438 | git checkout master && | |
439 | git push testrepo HEAD && | |
440 | check_push_result $the_commit heads/master | |
441 | ||
442 | ' | |
443 | ||
444 | test_expect_success 'push with HEAD nonexisting at remote' ' | |
445 | ||
446 | mk_test heads/master && | |
447 | git checkout -b local master && | |
448 | git push testrepo HEAD && | |
449 | check_push_result $the_commit heads/local | |
450 | ' | |
451 | ||
9f0ea7e8 DB |
452 | test_expect_success 'push with +HEAD' ' |
453 | ||
454 | mk_test heads/master && | |
455 | git checkout master && | |
456 | git branch -D local && | |
457 | git checkout -b local && | |
458 | git push testrepo master local && | |
459 | check_push_result $the_commit heads/master && | |
460 | check_push_result $the_commit heads/local && | |
461 | ||
462 | # Without force rewinding should fail | |
463 | git reset --hard HEAD^ && | |
d492b31c | 464 | test_must_fail git push testrepo HEAD && |
9f0ea7e8 DB |
465 | check_push_result $the_commit heads/local && |
466 | ||
467 | # With force rewinding should succeed | |
468 | git push testrepo +HEAD && | |
469 | check_push_result $the_first_commit heads/local | |
470 | ||
471 | ' | |
472 | ||
7be8b3ba | 473 | test_expect_success 'push HEAD with non-existent, incomplete dest' ' |
f8aae120 JK |
474 | |
475 | mk_test && | |
476 | git checkout master && | |
477 | git push testrepo HEAD:branch && | |
478 | check_push_result $the_commit heads/branch | |
479 | ||
480 | ' | |
481 | ||
9f0ea7e8 DB |
482 | test_expect_success 'push with config remote.*.push = HEAD' ' |
483 | ||
484 | mk_test heads/local && | |
485 | git checkout master && | |
486 | git branch -f local $the_commit && | |
487 | ( | |
488 | cd testrepo && | |
489 | git checkout local && | |
490 | git reset --hard $the_first_commit | |
491 | ) && | |
492 | git config remote.there.url testrepo && | |
493 | git config remote.there.push HEAD && | |
494 | git config branch.master.remote there && | |
495 | git push && | |
496 | check_push_result $the_commit heads/master && | |
497 | check_push_result $the_first_commit heads/local | |
498 | ' | |
499 | ||
500 | # clean up the cruft left with the previous one | |
501 | git config --remove-section remote.there | |
502 | git config --remove-section branch.master | |
503 | ||
e1ca4241 MG |
504 | test_expect_success 'push with config remote.*.pushurl' ' |
505 | ||
506 | mk_test heads/master && | |
507 | git checkout master && | |
508 | git config remote.there.url test2repo && | |
509 | git config remote.there.pushurl testrepo && | |
510 | git push there && | |
511 | check_push_result $the_commit heads/master | |
512 | ' | |
513 | ||
514 | # clean up the cruft left with the previous one | |
515 | git config --remove-section remote.there | |
516 | ||
11f2441f BE |
517 | test_expect_success 'push with dry-run' ' |
518 | ||
519 | mk_test heads/master && | |
d4785cd1 JS |
520 | ( |
521 | cd testrepo && | |
522 | old_commit=$(git show-ref -s --verify refs/heads/master) | |
523 | ) && | |
11f2441f BE |
524 | git push --dry-run testrepo && |
525 | check_push_result $old_commit heads/master | |
526 | ' | |
527 | ||
28391a80 JS |
528 | test_expect_success 'push updates local refs' ' |
529 | ||
b2dc968e JK |
530 | mk_test heads/master && |
531 | mk_child child && | |
d4785cd1 JS |
532 | ( |
533 | cd child && | |
b2dc968e | 534 | git pull .. master && |
28391a80 | 535 | git push && |
d4785cd1 JS |
536 | test $(git rev-parse master) = \ |
537 | $(git rev-parse remotes/origin/master) | |
538 | ) | |
28391a80 JS |
539 | |
540 | ' | |
541 | ||
16ed2f48 CB |
542 | test_expect_success 'push updates up-to-date local refs' ' |
543 | ||
b2dc968e JK |
544 | mk_test heads/master && |
545 | mk_child child1 && | |
546 | mk_child child2 && | |
547 | (cd child1 && git pull .. master && git push) && | |
d4785cd1 JS |
548 | ( |
549 | cd child2 && | |
16ed2f48 CB |
550 | git pull ../child1 master && |
551 | git push && | |
d4785cd1 JS |
552 | test $(git rev-parse master) = \ |
553 | $(git rev-parse remotes/origin/master) | |
554 | ) | |
16ed2f48 CB |
555 | |
556 | ' | |
557 | ||
558 | test_expect_success 'push preserves up-to-date packed refs' ' | |
559 | ||
b2dc968e JK |
560 | mk_test heads/master && |
561 | mk_child child && | |
d4785cd1 JS |
562 | ( |
563 | cd child && | |
16ed2f48 | 564 | git push && |
d4785cd1 JS |
565 | ! test -f .git/refs/remotes/origin/master |
566 | ) | |
16ed2f48 CB |
567 | |
568 | ' | |
569 | ||
28391a80 JS |
570 | test_expect_success 'push does not update local refs on failure' ' |
571 | ||
b2dc968e JK |
572 | mk_test heads/master && |
573 | mk_child child && | |
574 | mkdir testrepo/.git/hooks && | |
fc012c28 | 575 | echo "#!/no/frobnication/today" >testrepo/.git/hooks/pre-receive && |
b2dc968e | 576 | chmod +x testrepo/.git/hooks/pre-receive && |
d4785cd1 JS |
577 | ( |
578 | cd child && | |
b2dc968e | 579 | git pull .. master |
d492b31c | 580 | test_must_fail git push && |
28391a80 | 581 | test $(git rev-parse master) != \ |
d4785cd1 JS |
582 | $(git rev-parse remotes/origin/master) |
583 | ) | |
28391a80 JS |
584 | |
585 | ' | |
586 | ||
587 | test_expect_success 'allow deleting an invalid remote ref' ' | |
588 | ||
b2dc968e | 589 | mk_test heads/master && |
28391a80 JS |
590 | rm -f testrepo/.git/objects/??/* && |
591 | git push testrepo :refs/heads/master && | |
d492b31c | 592 | (cd testrepo && test_must_fail git rev-parse --verify refs/heads/master) |
28391a80 JS |
593 | |
594 | ' | |
595 | ||
160b81ed PYH |
596 | test_expect_success 'pushing valid refs triggers post-receive and post-update hooks' ' |
597 | mk_test_with_hooks heads/master heads/next && | |
598 | orgmaster=$(cd testrepo && git show-ref -s --verify refs/heads/master) && | |
599 | newmaster=$(git show-ref -s --verify refs/heads/master) && | |
600 | orgnext=$(cd testrepo && git show-ref -s --verify refs/heads/next) && | |
601 | newnext=$_z40 && | |
602 | git push testrepo refs/heads/master:refs/heads/master :refs/heads/next && | |
603 | ( | |
604 | cd testrepo/.git && | |
605 | cat >pre-receive.expect <<-EOF && | |
606 | $orgmaster $newmaster refs/heads/master | |
607 | $orgnext $newnext refs/heads/next | |
608 | EOF | |
609 | ||
610 | cat >update.expect <<-EOF && | |
611 | refs/heads/master $orgmaster $newmaster | |
612 | refs/heads/next $orgnext $newnext | |
613 | EOF | |
614 | ||
615 | cat >post-receive.expect <<-EOF && | |
616 | $orgmaster $newmaster refs/heads/master | |
617 | $orgnext $newnext refs/heads/next | |
618 | EOF | |
619 | ||
620 | cat >post-update.expect <<-EOF && | |
621 | refs/heads/master | |
622 | refs/heads/next | |
623 | EOF | |
624 | ||
625 | test_cmp pre-receive.expect pre-receive.actual && | |
626 | test_cmp update.expect update.actual && | |
627 | test_cmp post-receive.expect post-receive.actual && | |
628 | test_cmp post-update.expect post-update.actual | |
629 | ) | |
630 | ' | |
631 | ||
632 | test_expect_success 'deleting dangling ref triggers hooks with correct args' ' | |
633 | mk_test_with_hooks heads/master && | |
634 | rm -f testrepo/.git/objects/??/* && | |
635 | git push testrepo :refs/heads/master && | |
636 | ( | |
637 | cd testrepo/.git && | |
638 | cat >pre-receive.expect <<-EOF && | |
639 | $_z40 $_z40 refs/heads/master | |
640 | EOF | |
641 | ||
642 | cat >update.expect <<-EOF && | |
643 | refs/heads/master $_z40 $_z40 | |
644 | EOF | |
645 | ||
646 | cat >post-receive.expect <<-EOF && | |
647 | $_z40 $_z40 refs/heads/master | |
648 | EOF | |
649 | ||
650 | cat >post-update.expect <<-EOF && | |
651 | refs/heads/master | |
652 | EOF | |
653 | ||
654 | test_cmp pre-receive.expect pre-receive.actual && | |
655 | test_cmp update.expect update.actual && | |
656 | test_cmp post-receive.expect post-receive.actual && | |
657 | test_cmp post-update.expect post-update.actual | |
658 | ) | |
659 | ' | |
660 | ||
661 | test_expect_success 'deletion of a non-existent ref is not fed to post-receive and post-update hooks' ' | |
662 | mk_test_with_hooks heads/master && | |
663 | orgmaster=$(cd testrepo && git show-ref -s --verify refs/heads/master) && | |
664 | newmaster=$(git show-ref -s --verify refs/heads/master) && | |
665 | git push testrepo master :refs/heads/nonexistent && | |
666 | ( | |
667 | cd testrepo/.git && | |
668 | cat >pre-receive.expect <<-EOF && | |
669 | $orgmaster $newmaster refs/heads/master | |
670 | $_z40 $_z40 refs/heads/nonexistent | |
671 | EOF | |
672 | ||
673 | cat >update.expect <<-EOF && | |
674 | refs/heads/master $orgmaster $newmaster | |
675 | refs/heads/nonexistent $_z40 $_z40 | |
676 | EOF | |
677 | ||
678 | cat >post-receive.expect <<-EOF && | |
679 | $orgmaster $newmaster refs/heads/master | |
680 | EOF | |
681 | ||
682 | cat >post-update.expect <<-EOF && | |
683 | refs/heads/master | |
684 | EOF | |
685 | ||
686 | test_cmp pre-receive.expect pre-receive.actual && | |
687 | test_cmp update.expect update.actual && | |
688 | test_cmp post-receive.expect post-receive.actual && | |
689 | test_cmp post-update.expect post-update.actual | |
690 | ) | |
691 | ' | |
692 | ||
693 | test_expect_success 'deletion of a non-existent ref alone does trigger post-receive and post-update hooks' ' | |
694 | mk_test_with_hooks heads/master && | |
695 | git push testrepo :refs/heads/nonexistent && | |
696 | ( | |
697 | cd testrepo/.git && | |
698 | cat >pre-receive.expect <<-EOF && | |
699 | $_z40 $_z40 refs/heads/nonexistent | |
700 | EOF | |
701 | ||
702 | cat >update.expect <<-EOF && | |
703 | refs/heads/nonexistent $_z40 $_z40 | |
704 | EOF | |
705 | ||
706 | test_cmp pre-receive.expect pre-receive.actual && | |
707 | test_cmp update.expect update.actual && | |
708 | test_path_is_missing post-receive.actual && | |
709 | test_path_is_missing post-update.actual | |
710 | ) | |
711 | ' | |
712 | ||
713 | test_expect_success 'mixed ref updates, deletes, invalid deletes trigger hooks with correct input' ' | |
714 | mk_test_with_hooks heads/master heads/next heads/pu && | |
715 | orgmaster=$(cd testrepo && git show-ref -s --verify refs/heads/master) && | |
716 | newmaster=$(git show-ref -s --verify refs/heads/master) && | |
717 | orgnext=$(cd testrepo && git show-ref -s --verify refs/heads/next) && | |
718 | newnext=$_z40 && | |
719 | orgpu=$(cd testrepo && git show-ref -s --verify refs/heads/pu) && | |
720 | newpu=$(git show-ref -s --verify refs/heads/master) && | |
721 | git push testrepo refs/heads/master:refs/heads/master \ | |
722 | refs/heads/master:refs/heads/pu :refs/heads/next \ | |
723 | :refs/heads/nonexistent && | |
724 | ( | |
725 | cd testrepo/.git && | |
726 | cat >pre-receive.expect <<-EOF && | |
727 | $orgmaster $newmaster refs/heads/master | |
728 | $orgnext $newnext refs/heads/next | |
729 | $orgpu $newpu refs/heads/pu | |
730 | $_z40 $_z40 refs/heads/nonexistent | |
731 | EOF | |
732 | ||
733 | cat >update.expect <<-EOF && | |
734 | refs/heads/master $orgmaster $newmaster | |
735 | refs/heads/next $orgnext $newnext | |
736 | refs/heads/pu $orgpu $newpu | |
737 | refs/heads/nonexistent $_z40 $_z40 | |
738 | EOF | |
739 | ||
740 | cat >post-receive.expect <<-EOF && | |
741 | $orgmaster $newmaster refs/heads/master | |
742 | $orgnext $newnext refs/heads/next | |
743 | $orgpu $newpu refs/heads/pu | |
744 | EOF | |
745 | ||
746 | cat >post-update.expect <<-EOF && | |
747 | refs/heads/master | |
748 | refs/heads/next | |
749 | refs/heads/pu | |
750 | EOF | |
751 | ||
752 | test_cmp pre-receive.expect pre-receive.actual && | |
753 | test_cmp update.expect update.actual && | |
754 | test_cmp post-receive.expect post-receive.actual && | |
755 | test_cmp post-update.expect post-update.actual | |
756 | ) | |
757 | ' | |
758 | ||
f517f1f2 JK |
759 | test_expect_success 'allow deleting a ref using --delete' ' |
760 | mk_test heads/master && | |
761 | (cd testrepo && git config receive.denyDeleteCurrent warn) && | |
762 | git push testrepo --delete master && | |
763 | (cd testrepo && test_must_fail git rev-parse --verify refs/heads/master) | |
764 | ' | |
765 | ||
766 | test_expect_success 'allow deleting a tag using --delete' ' | |
767 | mk_test heads/master && | |
768 | git tag -a -m dummy_message deltag heads/master && | |
769 | git push testrepo --tags && | |
770 | (cd testrepo && git rev-parse --verify -q refs/tags/deltag) && | |
771 | git push testrepo --delete tag deltag && | |
772 | (cd testrepo && test_must_fail git rev-parse --verify refs/tags/deltag) | |
773 | ' | |
774 | ||
775 | test_expect_success 'push --delete without args aborts' ' | |
776 | mk_test heads/master && | |
777 | test_must_fail git push testrepo --delete | |
778 | ' | |
779 | ||
780 | test_expect_success 'push --delete refuses src:dest refspecs' ' | |
781 | mk_test heads/master && | |
782 | test_must_fail git push testrepo --delete master:foo | |
783 | ' | |
784 | ||
986e8239 | 785 | test_expect_success 'warn on push to HEAD of non-bare repository' ' |
a48fcd83 | 786 | mk_test heads/master && |
d4785cd1 JS |
787 | ( |
788 | cd testrepo && | |
986e8239 | 789 | git checkout master && |
d4785cd1 JS |
790 | git config receive.denyCurrentBranch warn |
791 | ) && | |
986e8239 | 792 | git push testrepo master 2>stderr && |
3d95d92b | 793 | grep "warning: updating the current branch" stderr |
986e8239 JK |
794 | ' |
795 | ||
796 | test_expect_success 'deny push to HEAD of non-bare repository' ' | |
a48fcd83 | 797 | mk_test heads/master && |
d4785cd1 JS |
798 | ( |
799 | cd testrepo && | |
986e8239 | 800 | git checkout master && |
d4785cd1 JS |
801 | git config receive.denyCurrentBranch true |
802 | ) && | |
986e8239 JK |
803 | test_must_fail git push testrepo master |
804 | ' | |
805 | ||
806 | test_expect_success 'allow push to HEAD of bare repository (bare)' ' | |
a48fcd83 | 807 | mk_test heads/master && |
d4785cd1 JS |
808 | ( |
809 | cd testrepo && | |
986e8239 JK |
810 | git checkout master && |
811 | git config receive.denyCurrentBranch true && | |
d4785cd1 JS |
812 | git config core.bare true |
813 | ) && | |
986e8239 | 814 | git push testrepo master 2>stderr && |
3d95d92b | 815 | ! grep "warning: updating the current branch" stderr |
986e8239 JK |
816 | ' |
817 | ||
818 | test_expect_success 'allow push to HEAD of non-bare repository (config)' ' | |
a48fcd83 | 819 | mk_test heads/master && |
d4785cd1 JS |
820 | ( |
821 | cd testrepo && | |
986e8239 JK |
822 | git checkout master && |
823 | git config receive.denyCurrentBranch false | |
824 | ) && | |
825 | git push testrepo master 2>stderr && | |
3d95d92b | 826 | ! grep "warning: updating the current branch" stderr |
986e8239 JK |
827 | ' |
828 | ||
18afe101 MK |
829 | test_expect_success 'fetch with branches' ' |
830 | mk_empty && | |
831 | git branch second $the_first_commit && | |
832 | git checkout second && | |
833 | echo ".." > testrepo/.git/branches/branch1 && | |
d4785cd1 JS |
834 | ( |
835 | cd testrepo && | |
18afe101 MK |
836 | git fetch branch1 && |
837 | r=$(git show-ref -s --verify refs/heads/branch1) && | |
838 | test "z$r" = "z$the_commit" && | |
839 | test 1 = $(git for-each-ref refs/heads | wc -l) | |
840 | ) && | |
841 | git checkout master | |
842 | ' | |
843 | ||
844 | test_expect_success 'fetch with branches containing #' ' | |
845 | mk_empty && | |
846 | echo "..#second" > testrepo/.git/branches/branch2 && | |
d4785cd1 JS |
847 | ( |
848 | cd testrepo && | |
18afe101 MK |
849 | git fetch branch2 && |
850 | r=$(git show-ref -s --verify refs/heads/branch2) && | |
851 | test "z$r" = "z$the_first_commit" && | |
852 | test 1 = $(git for-each-ref refs/heads | wc -l) | |
853 | ) && | |
854 | git checkout master | |
855 | ' | |
856 | ||
857 | test_expect_success 'push with branches' ' | |
858 | mk_empty && | |
859 | git checkout second && | |
860 | echo "testrepo" > .git/branches/branch1 && | |
861 | git push branch1 && | |
d4785cd1 JS |
862 | ( |
863 | cd testrepo && | |
18afe101 MK |
864 | r=$(git show-ref -s --verify refs/heads/master) && |
865 | test "z$r" = "z$the_first_commit" && | |
866 | test 1 = $(git for-each-ref refs/heads | wc -l) | |
867 | ) | |
868 | ' | |
869 | ||
870 | test_expect_success 'push with branches containing #' ' | |
871 | mk_empty && | |
872 | echo "testrepo#branch3" > .git/branches/branch2 && | |
873 | git push branch2 && | |
d4785cd1 JS |
874 | ( |
875 | cd testrepo && | |
18afe101 MK |
876 | r=$(git show-ref -s --verify refs/heads/branch3) && |
877 | test "z$r" = "z$the_first_commit" && | |
878 | test 1 = $(git for-each-ref refs/heads | wc -l) | |
879 | ) && | |
880 | git checkout master | |
881 | ' | |
882 | ||
da3efdb1 JS |
883 | test_expect_success 'push into aliased refs (consistent)' ' |
884 | mk_test heads/master && | |
885 | mk_child child1 && | |
886 | mk_child child2 && | |
887 | ( | |
888 | cd child1 && | |
889 | git branch foo && | |
890 | git symbolic-ref refs/heads/bar refs/heads/foo | |
891 | git config receive.denyCurrentBranch false | |
892 | ) && | |
893 | ( | |
894 | cd child2 && | |
895 | >path2 && | |
896 | git add path2 && | |
897 | test_tick && | |
898 | git commit -a -m child2 && | |
899 | git branch foo && | |
900 | git branch bar && | |
901 | git push ../child1 foo bar | |
902 | ) | |
903 | ' | |
904 | ||
905 | test_expect_success 'push into aliased refs (inconsistent)' ' | |
906 | mk_test heads/master && | |
907 | mk_child child1 && | |
908 | mk_child child2 && | |
909 | ( | |
910 | cd child1 && | |
911 | git branch foo && | |
912 | git symbolic-ref refs/heads/bar refs/heads/foo | |
913 | git config receive.denyCurrentBranch false | |
914 | ) && | |
915 | ( | |
916 | cd child2 && | |
917 | >path2 && | |
918 | git add path2 && | |
919 | test_tick && | |
920 | git commit -a -m child2 && | |
921 | git branch foo && | |
922 | >path3 && | |
923 | git add path3 && | |
924 | test_tick && | |
925 | git commit -a -m child2 && | |
926 | git branch bar && | |
927 | test_must_fail git push ../child1 foo bar 2>stderr && | |
928 | grep "refusing inconsistent update" stderr | |
929 | ) | |
930 | ' | |
931 | ||
dbfeddb1 CR |
932 | test_expect_success 'push requires --force to update lightweight tag' ' |
933 | mk_test heads/master && | |
934 | mk_child child1 && | |
935 | mk_child child2 && | |
936 | ( | |
937 | cd child1 && | |
938 | git tag Tag && | |
939 | git push ../child2 Tag && | |
940 | git push ../child2 Tag && | |
941 | >file1 && | |
942 | git add file1 && | |
943 | git commit -m "file1" && | |
944 | git tag -f Tag && | |
945 | test_must_fail git push ../child2 Tag && | |
946 | git push --force ../child2 Tag && | |
947 | git tag -f Tag && | |
948 | test_must_fail git push ../child2 Tag HEAD~ && | |
949 | git push --force ../child2 Tag | |
950 | ) | |
951 | ' | |
952 | ||
fbe4f447 LA |
953 | test_expect_success 'push --porcelain' ' |
954 | mk_empty && | |
955 | echo >.git/foo "To testrepo" && | |
956 | echo >>.git/foo "* refs/heads/master:refs/remotes/origin/master [new branch]" && | |
957 | echo >>.git/foo "Done" && | |
958 | git push >.git/bar --porcelain testrepo refs/heads/master:refs/remotes/origin/master && | |
959 | ( | |
960 | cd testrepo && | |
961 | r=$(git show-ref -s --verify refs/remotes/origin/master) && | |
962 | test "z$r" = "z$the_commit" && | |
963 | test 1 = $(git for-each-ref refs/remotes/origin | wc -l) | |
964 | ) && | |
c296134d | 965 | test_cmp .git/foo .git/bar |
fbe4f447 LA |
966 | ' |
967 | ||
968 | test_expect_success 'push --porcelain bad url' ' | |
969 | mk_empty && | |
970 | test_must_fail git push >.git/bar --porcelain asdfasdfasd refs/heads/master:refs/remotes/origin/master && | |
971 | test_must_fail grep -q Done .git/bar | |
972 | ' | |
973 | ||
974 | test_expect_success 'push --porcelain rejected' ' | |
975 | mk_empty && | |
976 | git push testrepo refs/heads/master:refs/remotes/origin/master && | |
977 | (cd testrepo && | |
978 | git reset --hard origin/master^ | |
979 | git config receive.denyCurrentBranch true) && | |
980 | ||
981 | echo >.git/foo "To testrepo" && | |
982 | echo >>.git/foo "! refs/heads/master:refs/heads/master [remote rejected] (branch is currently checked out)" && | |
983 | ||
984 | test_must_fail git push >.git/bar --porcelain testrepo refs/heads/master:refs/heads/master && | |
c296134d | 985 | test_cmp .git/foo .git/bar |
fbe4f447 LA |
986 | ' |
987 | ||
988 | test_expect_success 'push --porcelain --dry-run rejected' ' | |
989 | mk_empty && | |
990 | git push testrepo refs/heads/master:refs/remotes/origin/master && | |
991 | (cd testrepo && | |
992 | git reset --hard origin/master | |
993 | git config receive.denyCurrentBranch true) && | |
994 | ||
995 | echo >.git/foo "To testrepo" && | |
996 | echo >>.git/foo "! refs/heads/master^:refs/heads/master [rejected] (non-fast-forward)" && | |
997 | echo >>.git/foo "Done" && | |
998 | ||
999 | test_must_fail git push >.git/bar --porcelain --dry-run testrepo refs/heads/master^:refs/heads/master && | |
c296134d | 1000 | test_cmp .git/foo .git/bar |
fbe4f447 LA |
1001 | ' |
1002 | ||
6ddba5e2 FC |
1003 | test_expect_success 'push --prune' ' |
1004 | mk_test heads/master heads/second heads/foo heads/bar && | |
1005 | git push --prune testrepo && | |
1006 | check_push_result $the_commit heads/master && | |
1007 | check_push_result $the_first_commit heads/second && | |
1008 | ! check_push_result $the_first_commit heads/foo heads/bar | |
1009 | ' | |
1010 | ||
1011 | test_expect_success 'push --prune refspec' ' | |
1012 | mk_test tmp/master tmp/second tmp/foo tmp/bar && | |
1013 | git push --prune testrepo "refs/heads/*:refs/tmp/*" && | |
1014 | check_push_result $the_commit tmp/master && | |
1015 | check_push_result $the_first_commit tmp/second && | |
1016 | ! check_push_result $the_first_commit tmp/foo tmp/bar | |
1017 | ' | |
1018 | ||
daebaa78 JH |
1019 | for configsection in transfer receive |
1020 | do | |
1021 | test_expect_success "push to update a ref hidden by $configsection.hiderefs" ' | |
1022 | mk_test heads/master hidden/one hidden/two hidden/three && | |
1023 | ( | |
1024 | cd testrepo && | |
1025 | git config $configsection.hiderefs refs/hidden | |
1026 | ) && | |
1027 | ||
1028 | # push to unhidden ref succeeds normally | |
1029 | git push testrepo master:refs/heads/master && | |
1030 | check_push_result $the_commit heads/master && | |
1031 | ||
1032 | # push to update a hidden ref should fail | |
1033 | test_must_fail git push testrepo master:refs/hidden/one && | |
1034 | check_push_result $the_first_commit hidden/one && | |
1035 | ||
1036 | # push to delete a hidden ref should fail | |
1037 | test_must_fail git push testrepo :refs/hidden/two && | |
1038 | check_push_result $the_first_commit hidden/two && | |
1039 | ||
1040 | # idempotent push to update a hidden ref should fail | |
1041 | test_must_fail git push testrepo $the_first_commit:refs/hidden/three && | |
1042 | check_push_result $the_first_commit hidden/three | |
1043 | ' | |
1044 | done | |
1045 | ||
6e7b66ee JH |
1046 | test_expect_success 'fetch exact SHA1' ' |
1047 | mk_test heads/master hidden/one && | |
1048 | git push testrepo master:refs/hidden/one && | |
1049 | ( | |
1050 | cd testrepo && | |
1051 | git config transfer.hiderefs refs/hidden | |
1052 | ) && | |
1053 | check_push_result $the_commit hidden/one && | |
1054 | ||
1055 | mk_child child && | |
1056 | ( | |
1057 | cd child && | |
1058 | ||
1059 | # make sure $the_commit does not exist here | |
1060 | git repack -a -d && | |
1061 | git prune && | |
1062 | test_must_fail git cat-file -t $the_commit && | |
1063 | ||
1064 | # fetching the hidden object should fail by default | |
1065 | test_must_fail git fetch -v ../testrepo $the_commit:refs/heads/copy && | |
1066 | test_must_fail git rev-parse --verify refs/heads/copy && | |
1067 | ||
1068 | # the server side can allow it to succeed | |
1069 | ( | |
1070 | cd ../testrepo && | |
1071 | git config uploadpack.allowtipsha1inwant true | |
1072 | ) && | |
1073 | ||
1074 | git fetch -v ../testrepo $the_commit:refs/heads/copy && | |
1075 | result=$(git rev-parse --verify refs/heads/copy) && | |
1076 | test "$the_commit" = "$result" | |
1077 | ) | |
1078 | ' | |
1079 | ||
c2aba155 JH |
1080 | test_expect_success 'fetch follows tags by default' ' |
1081 | mk_test heads/master && | |
1082 | rm -fr src dst && | |
1083 | git init src && | |
1084 | ( | |
1085 | cd src && | |
1086 | git pull ../testrepo master && | |
1087 | git tag -m "annotated" tag && | |
1088 | git for-each-ref >tmp1 && | |
1089 | ( | |
1090 | cat tmp1 | |
1091 | sed -n "s|refs/heads/master$|refs/remotes/origin/master|p" tmp1 | |
1092 | ) | | |
1093 | sort -k 3 >../expect | |
1094 | ) && | |
1095 | git init dst && | |
1096 | ( | |
1097 | cd dst && | |
1098 | git remote add origin ../src && | |
1099 | git config branch.master.remote origin && | |
1100 | git config branch.master.merge refs/heads/master && | |
1101 | git pull && | |
1102 | git for-each-ref >../actual | |
1103 | ) && | |
1104 | test_cmp expect actual | |
1105 | ' | |
1106 | ||
1107 | test_expect_success 'push does not follow tags by default' ' | |
1108 | mk_test heads/master && | |
1109 | rm -fr src dst && | |
1110 | git init src && | |
1111 | git init --bare dst && | |
1112 | ( | |
1113 | cd src && | |
1114 | git pull ../testrepo master && | |
1115 | git tag -m "annotated" tag && | |
1116 | git checkout -b another && | |
1117 | git commit --allow-empty -m "future commit" && | |
1118 | git tag -m "future" future && | |
1119 | git checkout master && | |
1120 | git for-each-ref refs/heads/master >../expect && | |
1121 | git push ../dst master | |
1122 | ) && | |
1123 | ( | |
1124 | cd dst && | |
1125 | git for-each-ref >../actual | |
1126 | ) && | |
1127 | test_cmp expect actual | |
1128 | ' | |
1129 | ||
1130 | test_expect_success 'push --follow-tag only pushes relevant tags' ' | |
1131 | mk_test heads/master && | |
1132 | rm -fr src dst && | |
1133 | git init src && | |
1134 | git init --bare dst && | |
1135 | ( | |
1136 | cd src && | |
1137 | git pull ../testrepo master && | |
1138 | git tag -m "annotated" tag && | |
1139 | git checkout -b another && | |
1140 | git commit --allow-empty -m "future commit" && | |
1141 | git tag -m "future" future && | |
1142 | git checkout master && | |
1143 | git for-each-ref refs/heads/master refs/tags/tag >../expect | |
1144 | git push --follow-tag ../dst master | |
1145 | ) && | |
1146 | ( | |
1147 | cd dst && | |
1148 | git for-each-ref >../actual | |
1149 | ) && | |
1150 | test_cmp expect actual | |
1151 | ' | |
1152 | ||
bcdb34f7 | 1153 | test_done |