]>
Commit | Line | Data |
---|---|---|
1 | #!/bin/sh | |
2 | ||
3 | test_description='Basic fetch/push functionality. | |
4 | ||
5 | This test checks the following functionality: | |
6 | ||
7 | * command-line syntax | |
8 | * refspecs | |
9 | * fast-forward detection, and overriding it | |
10 | * configuration | |
11 | * hooks | |
12 | * --porcelain output format | |
13 | * hiderefs | |
14 | * reflogs | |
15 | * URL validation | |
16 | ' | |
17 | ||
18 | GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME=main | |
19 | export GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME | |
20 | ||
21 | TEST_CREATE_REPO_NO_TEMPLATE=1 | |
22 | . ./test-lib.sh | |
23 | ||
24 | D=$(pwd) | |
25 | ||
26 | mk_empty () { | |
27 | repo_name="$1" | |
28 | test_when_finished "rm -rf \"$repo_name\"" && | |
29 | test_path_is_missing "$repo_name" && | |
30 | git init --template= "$repo_name" && | |
31 | mkdir "$repo_name"/.git/hooks && | |
32 | git -C "$repo_name" config receive.denyCurrentBranch warn | |
33 | } | |
34 | ||
35 | mk_test () { | |
36 | repo_name="$1" | |
37 | shift | |
38 | ||
39 | mk_empty "$repo_name" && | |
40 | ( | |
41 | for ref in "$@" | |
42 | do | |
43 | git push "$repo_name" $the_first_commit:refs/$ref || | |
44 | exit | |
45 | done && | |
46 | cd "$repo_name" && | |
47 | for ref in "$@" | |
48 | do | |
49 | echo "$the_first_commit" >expect && | |
50 | git show-ref -s --verify refs/$ref >actual && | |
51 | test_cmp expect actual || | |
52 | exit | |
53 | done && | |
54 | git fsck --full | |
55 | ) | |
56 | } | |
57 | ||
58 | mk_test_with_hooks() { | |
59 | repo_name=$1 | |
60 | mk_test "$@" && | |
61 | test_hook -C "$repo_name" pre-receive <<-'EOF' && | |
62 | cat - >>pre-receive.actual | |
63 | EOF | |
64 | ||
65 | test_hook -C "$repo_name" update <<-'EOF' && | |
66 | printf "%s %s %s\n" "$@" >>update.actual | |
67 | EOF | |
68 | ||
69 | test_hook -C "$repo_name" post-receive <<-'EOF' && | |
70 | cat - >>post-receive.actual | |
71 | EOF | |
72 | ||
73 | test_hook -C "$repo_name" post-update <<-'EOF' | |
74 | for ref in "$@" | |
75 | do | |
76 | printf "%s\n" "$ref" >>post-update.actual | |
77 | done | |
78 | EOF | |
79 | } | |
80 | ||
81 | mk_child() { | |
82 | test_when_finished "rm -rf \"$2\"" && | |
83 | git clone --template= "$1" "$2" | |
84 | } | |
85 | ||
86 | check_push_result () { | |
87 | test $# -ge 3 || | |
88 | BUG "check_push_result requires at least 3 parameters" | |
89 | ||
90 | repo_name="$1" | |
91 | shift | |
92 | ||
93 | ( | |
94 | cd "$repo_name" && | |
95 | echo "$1" >expect && | |
96 | shift && | |
97 | for ref in "$@" | |
98 | do | |
99 | git show-ref -s --verify refs/$ref >actual && | |
100 | test_cmp expect actual || | |
101 | exit | |
102 | done && | |
103 | git fsck --full | |
104 | ) | |
105 | } | |
106 | ||
107 | test_expect_success setup ' | |
108 | ||
109 | >path1 && | |
110 | git add path1 && | |
111 | test_tick && | |
112 | git commit -a -m repo && | |
113 | the_first_commit=$(git show-ref -s --verify refs/heads/main) && | |
114 | ||
115 | >path2 && | |
116 | git add path2 && | |
117 | test_tick && | |
118 | git commit -a -m second && | |
119 | the_commit=$(git show-ref -s --verify refs/heads/main) | |
120 | ||
121 | ' | |
122 | ||
123 | for cmd in push fetch | |
124 | do | |
125 | for opt in ipv4 ipv6 | |
126 | do | |
127 | test_expect_success "reject 'git $cmd --no-$opt'" ' | |
128 | test_must_fail git $cmd --no-$opt 2>err && | |
129 | grep "unknown option .no-$opt" err | |
130 | ' | |
131 | done | |
132 | done | |
133 | ||
134 | test_expect_success 'fetch without wildcard' ' | |
135 | mk_empty testrepo && | |
136 | ( | |
137 | cd testrepo && | |
138 | git fetch .. refs/heads/main:refs/remotes/origin/main && | |
139 | ||
140 | echo "$the_commit commit refs/remotes/origin/main" >expect && | |
141 | git for-each-ref refs/remotes/origin >actual && | |
142 | test_cmp expect actual | |
143 | ) | |
144 | ' | |
145 | ||
146 | test_expect_success 'fetch with wildcard' ' | |
147 | mk_empty testrepo && | |
148 | ( | |
149 | cd testrepo && | |
150 | git config remote.up.url .. && | |
151 | git config remote.up.fetch "refs/heads/*:refs/remotes/origin/*" && | |
152 | git fetch up && | |
153 | ||
154 | echo "$the_commit commit refs/remotes/origin/main" >expect && | |
155 | git for-each-ref refs/remotes/origin >actual && | |
156 | test_cmp expect actual | |
157 | ) | |
158 | ' | |
159 | ||
160 | test_expect_success 'fetch with insteadOf' ' | |
161 | mk_empty testrepo && | |
162 | ( | |
163 | TRASH=$(pwd)/ && | |
164 | cd testrepo && | |
165 | git config "url.$TRASH.insteadOf" 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 | echo "$the_commit commit refs/remotes/origin/main" >expect && | |
171 | git for-each-ref refs/remotes/origin >actual && | |
172 | test_cmp expect actual | |
173 | ) | |
174 | ' | |
175 | ||
176 | test_expect_success 'fetch with pushInsteadOf (should not rewrite)' ' | |
177 | mk_empty testrepo && | |
178 | ( | |
179 | TRASH=$(pwd)/ && | |
180 | cd testrepo && | |
181 | git config "url.trash/.pushInsteadOf" "$TRASH" && | |
182 | git config remote.up.url "$TRASH." && | |
183 | git config remote.up.fetch "refs/heads/*:refs/remotes/origin/*" && | |
184 | git fetch up && | |
185 | ||
186 | echo "$the_commit commit refs/remotes/origin/main" >expect && | |
187 | git for-each-ref refs/remotes/origin >actual && | |
188 | test_cmp expect actual | |
189 | ) | |
190 | ' | |
191 | ||
192 | grep_wrote () { | |
193 | object_count=$1 | |
194 | file_name=$2 | |
195 | grep 'write_pack_file/wrote.*"value":"'$1'"' $2 | |
196 | } | |
197 | ||
198 | test_expect_success 'push without negotiation' ' | |
199 | mk_empty testrepo && | |
200 | git push testrepo $the_first_commit:refs/remotes/origin/first_commit && | |
201 | test_commit -C testrepo unrelated_commit && | |
202 | git -C testrepo config receive.hideRefs refs/remotes/origin/first_commit && | |
203 | test_when_finished "rm event" && | |
204 | GIT_TRACE2_EVENT="$(pwd)/event" git -c protocol.version=2 push testrepo refs/heads/main:refs/remotes/origin/main && | |
205 | grep_wrote 5 event # 2 commits, 2 trees, 1 blob | |
206 | ' | |
207 | ||
208 | test_expect_success 'push with negotiation' ' | |
209 | mk_empty testrepo && | |
210 | git push testrepo $the_first_commit:refs/remotes/origin/first_commit && | |
211 | test_commit -C testrepo unrelated_commit && | |
212 | git -C testrepo config receive.hideRefs refs/remotes/origin/first_commit && | |
213 | test_when_finished "rm event" && | |
214 | GIT_TRACE2_EVENT="$(pwd)/event" \ | |
215 | git -c protocol.version=2 -c push.negotiate=1 \ | |
216 | push testrepo refs/heads/main:refs/remotes/origin/main && | |
217 | grep \"key\":\"total_rounds\",\"value\":\"1\" event && | |
218 | grep_wrote 2 event # 1 commit, 1 tree | |
219 | ' | |
220 | ||
221 | test_expect_success 'push with negotiation proceeds anyway even if negotiation fails' ' | |
222 | mk_empty testrepo && | |
223 | git push testrepo $the_first_commit:refs/remotes/origin/first_commit && | |
224 | test_commit -C testrepo unrelated_commit && | |
225 | git -C testrepo config receive.hideRefs refs/remotes/origin/first_commit && | |
226 | test_when_finished "rm event" && | |
227 | GIT_TEST_PROTOCOL_VERSION=0 GIT_TRACE2_EVENT="$(pwd)/event" \ | |
228 | git -c push.negotiate=1 push testrepo refs/heads/main:refs/remotes/origin/main 2>err && | |
229 | grep_wrote 5 event && # 2 commits, 2 trees, 1 blob | |
230 | test_i18ngrep "push negotiation failed" err | |
231 | ' | |
232 | ||
233 | test_expect_success 'push with negotiation does not attempt to fetch submodules' ' | |
234 | mk_empty submodule_upstream && | |
235 | test_commit -C submodule_upstream submodule_commit && | |
236 | test_config_global protocol.file.allow always && | |
237 | git submodule add ./submodule_upstream submodule && | |
238 | mk_empty testrepo && | |
239 | git push testrepo $the_first_commit:refs/remotes/origin/first_commit && | |
240 | test_commit -C testrepo unrelated_commit && | |
241 | git -C testrepo config receive.hideRefs refs/remotes/origin/first_commit && | |
242 | GIT_TRACE2_EVENT="$(pwd)/event" git -c submodule.recurse=true \ | |
243 | -c protocol.version=2 -c push.negotiate=1 \ | |
244 | push testrepo refs/heads/main:refs/remotes/origin/main 2>err && | |
245 | grep \"key\":\"total_rounds\",\"value\":\"1\" event && | |
246 | ! grep "Fetching submodule" err | |
247 | ' | |
248 | ||
249 | test_expect_success 'push without wildcard' ' | |
250 | mk_empty testrepo && | |
251 | ||
252 | git push testrepo refs/heads/main:refs/remotes/origin/main && | |
253 | ( | |
254 | cd testrepo && | |
255 | echo "$the_commit commit refs/remotes/origin/main" >expect && | |
256 | git for-each-ref refs/remotes/origin >actual && | |
257 | test_cmp expect actual | |
258 | ) | |
259 | ' | |
260 | ||
261 | test_expect_success 'push with wildcard' ' | |
262 | mk_empty testrepo && | |
263 | ||
264 | git push testrepo "refs/heads/*:refs/remotes/origin/*" && | |
265 | ( | |
266 | cd testrepo && | |
267 | echo "$the_commit commit refs/remotes/origin/main" >expect && | |
268 | git for-each-ref refs/remotes/origin >actual && | |
269 | test_cmp expect actual | |
270 | ) | |
271 | ' | |
272 | ||
273 | test_expect_success 'push with insteadOf' ' | |
274 | mk_empty testrepo && | |
275 | TRASH="$(pwd)/" && | |
276 | test_config "url.$TRASH.insteadOf" trash/ && | |
277 | git push trash/testrepo refs/heads/main:refs/remotes/origin/main && | |
278 | ( | |
279 | cd testrepo && | |
280 | echo "$the_commit commit refs/remotes/origin/main" >expect && | |
281 | git for-each-ref refs/remotes/origin >actual && | |
282 | test_cmp expect actual | |
283 | ) | |
284 | ' | |
285 | ||
286 | test_expect_success 'push with pushInsteadOf' ' | |
287 | mk_empty testrepo && | |
288 | TRASH="$(pwd)/" && | |
289 | test_config "url.$TRASH.pushInsteadOf" trash/ && | |
290 | git push trash/testrepo refs/heads/main:refs/remotes/origin/main && | |
291 | ( | |
292 | cd testrepo && | |
293 | echo "$the_commit commit refs/remotes/origin/main" >expect && | |
294 | git for-each-ref refs/remotes/origin >actual && | |
295 | test_cmp expect actual | |
296 | ) | |
297 | ' | |
298 | ||
299 | test_expect_success 'push with pushInsteadOf and explicit pushurl (pushInsteadOf should not rewrite)' ' | |
300 | mk_empty testrepo && | |
301 | test_config "url.trash2/.pushInsteadOf" testrepo/ && | |
302 | test_config "url.trash3/.pushInsteadOf" trash/wrong && | |
303 | test_config remote.r.url trash/wrong && | |
304 | test_config remote.r.pushurl "testrepo/" && | |
305 | git push r refs/heads/main:refs/remotes/origin/main && | |
306 | ( | |
307 | cd testrepo && | |
308 | echo "$the_commit commit refs/remotes/origin/main" >expect && | |
309 | git for-each-ref refs/remotes/origin >actual && | |
310 | test_cmp expect actual | |
311 | ) | |
312 | ' | |
313 | ||
314 | test_expect_success 'push with matching heads' ' | |
315 | ||
316 | mk_test testrepo heads/main && | |
317 | git push testrepo : && | |
318 | check_push_result testrepo $the_commit heads/main | |
319 | ||
320 | ' | |
321 | ||
322 | test_expect_success 'push with matching heads on the command line' ' | |
323 | ||
324 | mk_test testrepo heads/main && | |
325 | git push testrepo : && | |
326 | check_push_result testrepo $the_commit heads/main | |
327 | ||
328 | ' | |
329 | ||
330 | test_expect_success 'failed (non-fast-forward) push with matching heads' ' | |
331 | ||
332 | mk_test testrepo heads/main && | |
333 | git push testrepo : && | |
334 | git commit --amend -massaged && | |
335 | test_must_fail git push testrepo && | |
336 | check_push_result testrepo $the_commit heads/main && | |
337 | git reset --hard $the_commit | |
338 | ||
339 | ' | |
340 | ||
341 | test_expect_success 'push --force with matching heads' ' | |
342 | ||
343 | mk_test testrepo heads/main && | |
344 | git push testrepo : && | |
345 | git commit --amend -massaged && | |
346 | git push --force testrepo : && | |
347 | ! check_push_result testrepo $the_commit heads/main && | |
348 | git reset --hard $the_commit | |
349 | ||
350 | ' | |
351 | ||
352 | test_expect_success 'push with matching heads and forced update' ' | |
353 | ||
354 | mk_test testrepo heads/main && | |
355 | git push testrepo : && | |
356 | git commit --amend -massaged && | |
357 | git push testrepo +: && | |
358 | ! check_push_result testrepo $the_commit heads/main && | |
359 | git reset --hard $the_commit | |
360 | ||
361 | ' | |
362 | ||
363 | test_expect_success 'push with no ambiguity (1)' ' | |
364 | ||
365 | mk_test testrepo heads/main && | |
366 | git push testrepo main:main && | |
367 | check_push_result testrepo $the_commit heads/main | |
368 | ||
369 | ' | |
370 | ||
371 | test_expect_success 'push with no ambiguity (2)' ' | |
372 | ||
373 | mk_test testrepo remotes/origin/main && | |
374 | git push testrepo main:origin/main && | |
375 | check_push_result testrepo $the_commit remotes/origin/main | |
376 | ||
377 | ' | |
378 | ||
379 | test_expect_success 'push with colon-less refspec, no ambiguity' ' | |
380 | ||
381 | mk_test testrepo heads/main heads/t/main && | |
382 | git branch -f t/main main && | |
383 | git push testrepo main && | |
384 | check_push_result testrepo $the_commit heads/main && | |
385 | check_push_result testrepo $the_first_commit heads/t/main | |
386 | ||
387 | ' | |
388 | ||
389 | test_expect_success 'push with weak ambiguity (1)' ' | |
390 | ||
391 | mk_test testrepo heads/main remotes/origin/main && | |
392 | git push testrepo main:main && | |
393 | check_push_result testrepo $the_commit heads/main && | |
394 | check_push_result testrepo $the_first_commit remotes/origin/main | |
395 | ||
396 | ' | |
397 | ||
398 | test_expect_success 'push with weak ambiguity (2)' ' | |
399 | ||
400 | mk_test testrepo heads/main remotes/origin/main remotes/another/main && | |
401 | git push testrepo main:main && | |
402 | check_push_result testrepo $the_commit heads/main && | |
403 | check_push_result testrepo $the_first_commit remotes/origin/main remotes/another/main | |
404 | ||
405 | ' | |
406 | ||
407 | test_expect_success 'push with ambiguity' ' | |
408 | ||
409 | mk_test testrepo heads/frotz tags/frotz && | |
410 | test_must_fail git push testrepo main:frotz && | |
411 | check_push_result testrepo $the_first_commit heads/frotz tags/frotz | |
412 | ||
413 | ' | |
414 | ||
415 | test_expect_success 'push with onelevel ref' ' | |
416 | mk_test testrepo heads/main && | |
417 | test_must_fail git push testrepo HEAD:refs/onelevel | |
418 | ' | |
419 | ||
420 | test_expect_success 'push with colon-less refspec (1)' ' | |
421 | ||
422 | mk_test testrepo heads/frotz tags/frotz && | |
423 | git branch -f frotz main && | |
424 | git push testrepo frotz && | |
425 | check_push_result testrepo $the_commit heads/frotz && | |
426 | check_push_result testrepo $the_first_commit tags/frotz | |
427 | ||
428 | ' | |
429 | ||
430 | test_expect_success 'push with colon-less refspec (2)' ' | |
431 | ||
432 | mk_test testrepo heads/frotz tags/frotz && | |
433 | if git show-ref --verify -q refs/heads/frotz | |
434 | then | |
435 | git branch -D frotz | |
436 | fi && | |
437 | git tag -f frotz && | |
438 | git push -f testrepo frotz && | |
439 | check_push_result testrepo $the_commit tags/frotz && | |
440 | check_push_result testrepo $the_first_commit heads/frotz | |
441 | ||
442 | ' | |
443 | ||
444 | test_expect_success 'push with colon-less refspec (3)' ' | |
445 | ||
446 | mk_test testrepo && | |
447 | if git show-ref --verify -q refs/tags/frotz | |
448 | then | |
449 | git tag -d frotz | |
450 | fi && | |
451 | git branch -f frotz main && | |
452 | git push testrepo frotz && | |
453 | check_push_result testrepo $the_commit heads/frotz && | |
454 | test 1 = $( cd testrepo && git show-ref | wc -l ) | |
455 | ' | |
456 | ||
457 | test_expect_success 'push with colon-less refspec (4)' ' | |
458 | ||
459 | mk_test testrepo && | |
460 | if git show-ref --verify -q refs/heads/frotz | |
461 | then | |
462 | git branch -D frotz | |
463 | fi && | |
464 | git tag -f frotz && | |
465 | git push testrepo frotz && | |
466 | check_push_result testrepo $the_commit tags/frotz && | |
467 | test 1 = $( cd testrepo && git show-ref | wc -l ) | |
468 | ||
469 | ' | |
470 | ||
471 | test_expect_success 'push head with non-existent, incomplete dest' ' | |
472 | ||
473 | mk_test testrepo && | |
474 | git push testrepo main:branch && | |
475 | check_push_result testrepo $the_commit heads/branch | |
476 | ||
477 | ' | |
478 | ||
479 | test_expect_success 'push tag with non-existent, incomplete dest' ' | |
480 | ||
481 | mk_test testrepo && | |
482 | git tag -f v1.0 && | |
483 | git push testrepo v1.0:tag && | |
484 | check_push_result testrepo $the_commit tags/tag | |
485 | ||
486 | ' | |
487 | ||
488 | test_expect_success 'push sha1 with non-existent, incomplete dest' ' | |
489 | ||
490 | mk_test testrepo && | |
491 | test_must_fail git push testrepo $(git rev-parse main):foo | |
492 | ||
493 | ' | |
494 | ||
495 | test_expect_success 'push ref expression with non-existent, incomplete dest' ' | |
496 | ||
497 | mk_test testrepo && | |
498 | test_must_fail git push testrepo main^:branch | |
499 | ||
500 | ' | |
501 | ||
502 | for head in HEAD @ | |
503 | do | |
504 | ||
505 | test_expect_success "push with $head" ' | |
506 | mk_test testrepo heads/main && | |
507 | git checkout main && | |
508 | git push testrepo $head && | |
509 | check_push_result testrepo $the_commit heads/main | |
510 | ' | |
511 | ||
512 | test_expect_success "push with $head nonexisting at remote" ' | |
513 | mk_test testrepo heads/main && | |
514 | git checkout -b local main && | |
515 | test_when_finished "git checkout main; git branch -D local" && | |
516 | git push testrepo $head && | |
517 | check_push_result testrepo $the_commit heads/local | |
518 | ' | |
519 | ||
520 | test_expect_success "push with +$head" ' | |
521 | mk_test testrepo heads/main && | |
522 | git checkout -b local main && | |
523 | test_when_finished "git checkout main; git branch -D local" && | |
524 | git push testrepo main local && | |
525 | check_push_result testrepo $the_commit heads/main && | |
526 | check_push_result testrepo $the_commit heads/local && | |
527 | ||
528 | # Without force rewinding should fail | |
529 | git reset --hard $head^ && | |
530 | test_must_fail git push testrepo $head && | |
531 | check_push_result testrepo $the_commit heads/local && | |
532 | ||
533 | # With force rewinding should succeed | |
534 | git push testrepo +$head && | |
535 | check_push_result testrepo $the_first_commit heads/local | |
536 | ' | |
537 | ||
538 | test_expect_success "push $head with non-existent, incomplete dest" ' | |
539 | mk_test testrepo && | |
540 | git checkout main && | |
541 | git push testrepo $head:branch && | |
542 | check_push_result testrepo $the_commit heads/branch | |
543 | ||
544 | ' | |
545 | ||
546 | test_expect_success "push with config remote.*.push = $head" ' | |
547 | mk_test testrepo heads/local && | |
548 | git checkout main && | |
549 | git branch -f local $the_commit && | |
550 | test_when_finished "git branch -D local" && | |
551 | ( | |
552 | cd testrepo && | |
553 | git checkout local && | |
554 | git reset --hard $the_first_commit | |
555 | ) && | |
556 | test_config remote.there.url testrepo && | |
557 | test_config remote.there.push $head && | |
558 | test_config branch.main.remote there && | |
559 | git push && | |
560 | check_push_result testrepo $the_commit heads/main && | |
561 | check_push_result testrepo $the_first_commit heads/local | |
562 | ' | |
563 | ||
564 | done | |
565 | ||
566 | test_expect_success "push to remote with no explicit refspec and config remote.*.push = src:dest" ' | |
567 | mk_test testrepo heads/main && | |
568 | git checkout $the_first_commit && | |
569 | test_config remote.there.url testrepo && | |
570 | test_config remote.there.push refs/heads/main:refs/heads/main && | |
571 | git push there && | |
572 | check_push_result testrepo $the_commit heads/main | |
573 | ' | |
574 | ||
575 | test_expect_success 'push with remote.pushdefault' ' | |
576 | mk_test up_repo heads/main && | |
577 | mk_test down_repo heads/main && | |
578 | test_config remote.up.url up_repo && | |
579 | test_config remote.down.url down_repo && | |
580 | test_config branch.main.remote up && | |
581 | test_config remote.pushdefault down && | |
582 | test_config push.default matching && | |
583 | git push && | |
584 | check_push_result up_repo $the_first_commit heads/main && | |
585 | check_push_result down_repo $the_commit heads/main | |
586 | ' | |
587 | ||
588 | test_expect_success 'push with config remote.*.pushurl' ' | |
589 | ||
590 | mk_test testrepo heads/main && | |
591 | git checkout main && | |
592 | test_config remote.there.url test2repo && | |
593 | test_config remote.there.pushurl testrepo && | |
594 | git push there : && | |
595 | check_push_result testrepo $the_commit heads/main | |
596 | ' | |
597 | ||
598 | test_expect_success 'push with config branch.*.pushremote' ' | |
599 | mk_test up_repo heads/main && | |
600 | mk_test side_repo heads/main && | |
601 | mk_test down_repo heads/main && | |
602 | test_config remote.up.url up_repo && | |
603 | test_config remote.pushdefault side_repo && | |
604 | test_config remote.down.url down_repo && | |
605 | test_config branch.main.remote up && | |
606 | test_config branch.main.pushremote down && | |
607 | test_config push.default matching && | |
608 | git push && | |
609 | check_push_result up_repo $the_first_commit heads/main && | |
610 | check_push_result side_repo $the_first_commit heads/main && | |
611 | check_push_result down_repo $the_commit heads/main | |
612 | ' | |
613 | ||
614 | test_expect_success 'branch.*.pushremote config order is irrelevant' ' | |
615 | mk_test one_repo heads/main && | |
616 | mk_test two_repo heads/main && | |
617 | test_config remote.one.url one_repo && | |
618 | test_config remote.two.url two_repo && | |
619 | test_config branch.main.pushremote two_repo && | |
620 | test_config remote.pushdefault one_repo && | |
621 | test_config push.default matching && | |
622 | git push && | |
623 | check_push_result one_repo $the_first_commit heads/main && | |
624 | check_push_result two_repo $the_commit heads/main | |
625 | ' | |
626 | ||
627 | test_expect_success 'push rejects empty branch name entries' ' | |
628 | mk_test one_repo heads/main && | |
629 | test_config remote.one.url one_repo && | |
630 | test_config branch..remote one && | |
631 | test_config branch..merge refs/heads/ && | |
632 | test_config branch.main.remote one && | |
633 | test_config branch.main.merge refs/heads/main && | |
634 | test_must_fail git push 2>err && | |
635 | grep "bad config variable .branch\.\." err | |
636 | ' | |
637 | ||
638 | test_expect_success 'push ignores "branch." config without subsection' ' | |
639 | mk_test one_repo heads/main && | |
640 | test_config remote.one.url one_repo && | |
641 | test_config branch.autoSetupMerge true && | |
642 | test_config branch.main.remote one && | |
643 | test_config branch.main.merge refs/heads/main && | |
644 | git push | |
645 | ' | |
646 | ||
647 | test_expect_success 'push with dry-run' ' | |
648 | ||
649 | mk_test testrepo heads/main && | |
650 | old_commit=$(git -C testrepo show-ref -s --verify refs/heads/main) && | |
651 | git push --dry-run testrepo : && | |
652 | check_push_result testrepo $old_commit heads/main | |
653 | ' | |
654 | ||
655 | test_expect_success 'push updates local refs' ' | |
656 | ||
657 | mk_test testrepo heads/main && | |
658 | mk_child testrepo child && | |
659 | ( | |
660 | cd child && | |
661 | git pull .. main && | |
662 | git push && | |
663 | test $(git rev-parse main) = \ | |
664 | $(git rev-parse remotes/origin/main) | |
665 | ) | |
666 | ||
667 | ' | |
668 | ||
669 | test_expect_success 'push updates up-to-date local refs' ' | |
670 | ||
671 | mk_test testrepo heads/main && | |
672 | mk_child testrepo child1 && | |
673 | mk_child testrepo child2 && | |
674 | (cd child1 && git pull .. main && git push) && | |
675 | ( | |
676 | cd child2 && | |
677 | git pull ../child1 main && | |
678 | git push && | |
679 | test $(git rev-parse main) = \ | |
680 | $(git rev-parse remotes/origin/main) | |
681 | ) | |
682 | ||
683 | ' | |
684 | ||
685 | test_expect_success 'push preserves up-to-date packed refs' ' | |
686 | ||
687 | mk_test testrepo heads/main && | |
688 | mk_child testrepo child && | |
689 | ( | |
690 | cd child && | |
691 | git push && | |
692 | ! test -f .git/refs/remotes/origin/main | |
693 | ) | |
694 | ||
695 | ' | |
696 | ||
697 | test_expect_success 'push does not update local refs on failure' ' | |
698 | ||
699 | mk_test testrepo heads/main && | |
700 | mk_child testrepo child && | |
701 | echo "#!/no/frobnication/today" >testrepo/.git/hooks/pre-receive && | |
702 | chmod +x testrepo/.git/hooks/pre-receive && | |
703 | ( | |
704 | cd child && | |
705 | git pull .. main && | |
706 | test_must_fail git push && | |
707 | test $(git rev-parse main) != \ | |
708 | $(git rev-parse remotes/origin/main) | |
709 | ) | |
710 | ||
711 | ' | |
712 | ||
713 | test_expect_success 'allow deleting an invalid remote ref' ' | |
714 | ||
715 | mk_test testrepo heads/branch && | |
716 | rm -f testrepo/.git/objects/??/* && | |
717 | git push testrepo :refs/heads/branch && | |
718 | (cd testrepo && test_must_fail git rev-parse --verify refs/heads/branch) | |
719 | ||
720 | ' | |
721 | ||
722 | test_expect_success 'pushing valid refs triggers post-receive and post-update hooks' ' | |
723 | mk_test_with_hooks testrepo heads/main heads/next && | |
724 | orgmain=$(cd testrepo && git show-ref -s --verify refs/heads/main) && | |
725 | newmain=$(git show-ref -s --verify refs/heads/main) && | |
726 | orgnext=$(cd testrepo && git show-ref -s --verify refs/heads/next) && | |
727 | newnext=$ZERO_OID && | |
728 | git push testrepo refs/heads/main:refs/heads/main :refs/heads/next && | |
729 | ( | |
730 | cd testrepo/.git && | |
731 | cat >pre-receive.expect <<-EOF && | |
732 | $orgmain $newmain refs/heads/main | |
733 | $orgnext $newnext refs/heads/next | |
734 | EOF | |
735 | ||
736 | cat >update.expect <<-EOF && | |
737 | refs/heads/main $orgmain $newmain | |
738 | refs/heads/next $orgnext $newnext | |
739 | EOF | |
740 | ||
741 | cat >post-receive.expect <<-EOF && | |
742 | $orgmain $newmain refs/heads/main | |
743 | $orgnext $newnext refs/heads/next | |
744 | EOF | |
745 | ||
746 | cat >post-update.expect <<-EOF && | |
747 | refs/heads/main | |
748 | refs/heads/next | |
749 | EOF | |
750 | ||
751 | test_cmp pre-receive.expect pre-receive.actual && | |
752 | test_cmp update.expect update.actual && | |
753 | test_cmp post-receive.expect post-receive.actual && | |
754 | test_cmp post-update.expect post-update.actual | |
755 | ) | |
756 | ' | |
757 | ||
758 | test_expect_success 'deleting dangling ref triggers hooks with correct args' ' | |
759 | mk_test_with_hooks testrepo heads/branch && | |
760 | orig=$(git -C testrepo rev-parse refs/heads/branch) && | |
761 | rm -f testrepo/.git/objects/??/* && | |
762 | git push testrepo :refs/heads/branch && | |
763 | ( | |
764 | cd testrepo/.git && | |
765 | cat >pre-receive.expect <<-EOF && | |
766 | $orig $ZERO_OID refs/heads/branch | |
767 | EOF | |
768 | ||
769 | cat >update.expect <<-EOF && | |
770 | refs/heads/branch $orig $ZERO_OID | |
771 | EOF | |
772 | ||
773 | cat >post-receive.expect <<-EOF && | |
774 | $orig $ZERO_OID refs/heads/branch | |
775 | EOF | |
776 | ||
777 | cat >post-update.expect <<-EOF && | |
778 | refs/heads/branch | |
779 | EOF | |
780 | ||
781 | test_cmp pre-receive.expect pre-receive.actual && | |
782 | test_cmp update.expect update.actual && | |
783 | test_cmp post-receive.expect post-receive.actual && | |
784 | test_cmp post-update.expect post-update.actual | |
785 | ) | |
786 | ' | |
787 | ||
788 | test_expect_success 'deletion of a non-existent ref is not fed to post-receive and post-update hooks' ' | |
789 | mk_test_with_hooks testrepo heads/main && | |
790 | orgmain=$(cd testrepo && git show-ref -s --verify refs/heads/main) && | |
791 | newmain=$(git show-ref -s --verify refs/heads/main) && | |
792 | git push testrepo main :refs/heads/nonexistent && | |
793 | ( | |
794 | cd testrepo/.git && | |
795 | cat >pre-receive.expect <<-EOF && | |
796 | $orgmain $newmain refs/heads/main | |
797 | $ZERO_OID $ZERO_OID refs/heads/nonexistent | |
798 | EOF | |
799 | ||
800 | cat >update.expect <<-EOF && | |
801 | refs/heads/main $orgmain $newmain | |
802 | refs/heads/nonexistent $ZERO_OID $ZERO_OID | |
803 | EOF | |
804 | ||
805 | cat >post-receive.expect <<-EOF && | |
806 | $orgmain $newmain refs/heads/main | |
807 | EOF | |
808 | ||
809 | cat >post-update.expect <<-EOF && | |
810 | refs/heads/main | |
811 | EOF | |
812 | ||
813 | test_cmp pre-receive.expect pre-receive.actual && | |
814 | test_cmp update.expect update.actual && | |
815 | test_cmp post-receive.expect post-receive.actual && | |
816 | test_cmp post-update.expect post-update.actual | |
817 | ) | |
818 | ' | |
819 | ||
820 | test_expect_success 'deletion of a non-existent ref alone does trigger post-receive and post-update hooks' ' | |
821 | mk_test_with_hooks testrepo heads/main && | |
822 | git push testrepo :refs/heads/nonexistent && | |
823 | ( | |
824 | cd testrepo/.git && | |
825 | cat >pre-receive.expect <<-EOF && | |
826 | $ZERO_OID $ZERO_OID refs/heads/nonexistent | |
827 | EOF | |
828 | ||
829 | cat >update.expect <<-EOF && | |
830 | refs/heads/nonexistent $ZERO_OID $ZERO_OID | |
831 | EOF | |
832 | ||
833 | test_cmp pre-receive.expect pre-receive.actual && | |
834 | test_cmp update.expect update.actual && | |
835 | test_path_is_missing post-receive.actual && | |
836 | test_path_is_missing post-update.actual | |
837 | ) | |
838 | ' | |
839 | ||
840 | test_expect_success 'mixed ref updates, deletes, invalid deletes trigger hooks with correct input' ' | |
841 | mk_test_with_hooks testrepo heads/main heads/next heads/seen && | |
842 | orgmain=$(cd testrepo && git show-ref -s --verify refs/heads/main) && | |
843 | newmain=$(git show-ref -s --verify refs/heads/main) && | |
844 | orgnext=$(cd testrepo && git show-ref -s --verify refs/heads/next) && | |
845 | newnext=$ZERO_OID && | |
846 | orgseen=$(cd testrepo && git show-ref -s --verify refs/heads/seen) && | |
847 | newseen=$(git show-ref -s --verify refs/heads/main) && | |
848 | git push testrepo refs/heads/main:refs/heads/main \ | |
849 | refs/heads/main:refs/heads/seen :refs/heads/next \ | |
850 | :refs/heads/nonexistent && | |
851 | ( | |
852 | cd testrepo/.git && | |
853 | cat >pre-receive.expect <<-EOF && | |
854 | $orgmain $newmain refs/heads/main | |
855 | $orgnext $newnext refs/heads/next | |
856 | $orgseen $newseen refs/heads/seen | |
857 | $ZERO_OID $ZERO_OID refs/heads/nonexistent | |
858 | EOF | |
859 | ||
860 | cat >update.expect <<-EOF && | |
861 | refs/heads/main $orgmain $newmain | |
862 | refs/heads/next $orgnext $newnext | |
863 | refs/heads/seen $orgseen $newseen | |
864 | refs/heads/nonexistent $ZERO_OID $ZERO_OID | |
865 | EOF | |
866 | ||
867 | cat >post-receive.expect <<-EOF && | |
868 | $orgmain $newmain refs/heads/main | |
869 | $orgnext $newnext refs/heads/next | |
870 | $orgseen $newseen refs/heads/seen | |
871 | EOF | |
872 | ||
873 | cat >post-update.expect <<-EOF && | |
874 | refs/heads/main | |
875 | refs/heads/next | |
876 | refs/heads/seen | |
877 | EOF | |
878 | ||
879 | test_cmp pre-receive.expect pre-receive.actual && | |
880 | test_cmp update.expect update.actual && | |
881 | test_cmp post-receive.expect post-receive.actual && | |
882 | test_cmp post-update.expect post-update.actual | |
883 | ) | |
884 | ' | |
885 | ||
886 | test_expect_success 'allow deleting a ref using --delete' ' | |
887 | mk_test testrepo heads/main && | |
888 | (cd testrepo && git config receive.denyDeleteCurrent warn) && | |
889 | git push testrepo --delete main && | |
890 | (cd testrepo && test_must_fail git rev-parse --verify refs/heads/main) | |
891 | ' | |
892 | ||
893 | test_expect_success 'allow deleting a tag using --delete' ' | |
894 | mk_test testrepo heads/main && | |
895 | git tag -a -m dummy_message deltag heads/main && | |
896 | git push testrepo --tags && | |
897 | (cd testrepo && git rev-parse --verify -q refs/tags/deltag) && | |
898 | git push testrepo --delete tag deltag && | |
899 | (cd testrepo && test_must_fail git rev-parse --verify refs/tags/deltag) | |
900 | ' | |
901 | ||
902 | test_expect_success 'push --delete without args aborts' ' | |
903 | mk_test testrepo heads/main && | |
904 | test_must_fail git push testrepo --delete | |
905 | ' | |
906 | ||
907 | test_expect_success 'push --delete refuses src:dest refspecs' ' | |
908 | mk_test testrepo heads/main && | |
909 | test_must_fail git push testrepo --delete main:foo | |
910 | ' | |
911 | ||
912 | test_expect_success 'push --delete refuses empty string' ' | |
913 | mk_test testrepo heads/master && | |
914 | test_must_fail git push testrepo --delete "" | |
915 | ' | |
916 | ||
917 | test_expect_success 'push --delete onelevel refspecs' ' | |
918 | mk_test testrepo heads/main && | |
919 | git -C testrepo update-ref refs/onelevel refs/heads/main && | |
920 | git push testrepo --delete refs/onelevel && | |
921 | test_must_fail git -C testrepo rev-parse --verify refs/onelevel | |
922 | ' | |
923 | ||
924 | test_expect_success 'warn on push to HEAD of non-bare repository' ' | |
925 | mk_test testrepo heads/main && | |
926 | ( | |
927 | cd testrepo && | |
928 | git checkout main && | |
929 | git config receive.denyCurrentBranch warn | |
930 | ) && | |
931 | git push testrepo main 2>stderr && | |
932 | grep "warning: updating the current branch" stderr | |
933 | ' | |
934 | ||
935 | test_expect_success 'deny push to HEAD of non-bare repository' ' | |
936 | mk_test testrepo heads/main && | |
937 | ( | |
938 | cd testrepo && | |
939 | git checkout main && | |
940 | git config receive.denyCurrentBranch true | |
941 | ) && | |
942 | test_must_fail git push testrepo main | |
943 | ' | |
944 | ||
945 | test_expect_success 'allow push to HEAD of bare repository (bare)' ' | |
946 | mk_test testrepo heads/main && | |
947 | ( | |
948 | cd testrepo && | |
949 | git checkout main && | |
950 | git config receive.denyCurrentBranch true && | |
951 | git config core.bare true | |
952 | ) && | |
953 | git push testrepo main 2>stderr && | |
954 | ! grep "warning: updating the current branch" stderr | |
955 | ' | |
956 | ||
957 | test_expect_success 'allow push to HEAD of non-bare repository (config)' ' | |
958 | mk_test testrepo heads/main && | |
959 | ( | |
960 | cd testrepo && | |
961 | git checkout main && | |
962 | git config receive.denyCurrentBranch false | |
963 | ) && | |
964 | git push testrepo main 2>stderr && | |
965 | ! grep "warning: updating the current branch" stderr | |
966 | ' | |
967 | ||
968 | test_expect_success 'fetch with branches' ' | |
969 | mk_empty testrepo && | |
970 | git branch second $the_first_commit && | |
971 | git checkout second && | |
972 | mkdir testrepo/.git/branches && | |
973 | echo ".." > testrepo/.git/branches/branch1 && | |
974 | ( | |
975 | cd testrepo && | |
976 | git fetch branch1 && | |
977 | echo "$the_commit commit refs/heads/branch1" >expect && | |
978 | git for-each-ref refs/heads >actual && | |
979 | test_cmp expect actual | |
980 | ) && | |
981 | git checkout main | |
982 | ' | |
983 | ||
984 | test_expect_success 'fetch with branches containing #' ' | |
985 | mk_empty testrepo && | |
986 | mkdir testrepo/.git/branches && | |
987 | echo "..#second" > testrepo/.git/branches/branch2 && | |
988 | ( | |
989 | cd testrepo && | |
990 | git fetch branch2 && | |
991 | echo "$the_first_commit commit refs/heads/branch2" >expect && | |
992 | git for-each-ref refs/heads >actual && | |
993 | test_cmp expect actual | |
994 | ) && | |
995 | git checkout main | |
996 | ' | |
997 | ||
998 | test_expect_success 'push with branches' ' | |
999 | mk_empty testrepo && | |
1000 | git checkout second && | |
1001 | ||
1002 | test_when_finished "rm -rf .git/branches" && | |
1003 | mkdir .git/branches && | |
1004 | echo "testrepo" > .git/branches/branch1 && | |
1005 | ||
1006 | git push branch1 && | |
1007 | ( | |
1008 | cd testrepo && | |
1009 | echo "$the_first_commit commit refs/heads/main" >expect && | |
1010 | git for-each-ref refs/heads >actual && | |
1011 | test_cmp expect actual | |
1012 | ) | |
1013 | ' | |
1014 | ||
1015 | test_expect_success 'push with branches containing #' ' | |
1016 | mk_empty testrepo && | |
1017 | ||
1018 | test_when_finished "rm -rf .git/branches" && | |
1019 | mkdir .git/branches && | |
1020 | echo "testrepo#branch3" > .git/branches/branch2 && | |
1021 | ||
1022 | git push branch2 && | |
1023 | ( | |
1024 | cd testrepo && | |
1025 | echo "$the_first_commit commit refs/heads/branch3" >expect && | |
1026 | git for-each-ref refs/heads >actual && | |
1027 | test_cmp expect actual | |
1028 | ) && | |
1029 | git checkout main | |
1030 | ' | |
1031 | ||
1032 | test_expect_success 'push into aliased refs (consistent)' ' | |
1033 | mk_test testrepo heads/main && | |
1034 | mk_child testrepo child1 && | |
1035 | mk_child testrepo child2 && | |
1036 | ( | |
1037 | cd child1 && | |
1038 | git branch foo && | |
1039 | git symbolic-ref refs/heads/bar refs/heads/foo && | |
1040 | git config receive.denyCurrentBranch false | |
1041 | ) && | |
1042 | ( | |
1043 | cd child2 && | |
1044 | >path2 && | |
1045 | git add path2 && | |
1046 | test_tick && | |
1047 | git commit -a -m child2 && | |
1048 | git branch foo && | |
1049 | git branch bar && | |
1050 | git push ../child1 foo bar | |
1051 | ) | |
1052 | ' | |
1053 | ||
1054 | test_expect_success 'push into aliased refs (inconsistent)' ' | |
1055 | mk_test testrepo heads/main && | |
1056 | mk_child testrepo child1 && | |
1057 | mk_child testrepo child2 && | |
1058 | ( | |
1059 | cd child1 && | |
1060 | git branch foo && | |
1061 | git symbolic-ref refs/heads/bar refs/heads/foo && | |
1062 | git config receive.denyCurrentBranch false | |
1063 | ) && | |
1064 | ( | |
1065 | cd child2 && | |
1066 | >path2 && | |
1067 | git add path2 && | |
1068 | test_tick && | |
1069 | git commit -a -m child2 && | |
1070 | git branch foo && | |
1071 | >path3 && | |
1072 | git add path3 && | |
1073 | test_tick && | |
1074 | git commit -a -m child2 && | |
1075 | git branch bar && | |
1076 | test_must_fail git push ../child1 foo bar 2>stderr && | |
1077 | grep "refusing inconsistent update" stderr | |
1078 | ) | |
1079 | ' | |
1080 | ||
1081 | test_force_push_tag () { | |
1082 | tag_type_description=$1 | |
1083 | tag_args=$2 | |
1084 | ||
1085 | test_expect_success "force pushing required to update $tag_type_description" " | |
1086 | mk_test testrepo heads/main && | |
1087 | mk_child testrepo child1 && | |
1088 | mk_child testrepo child2 && | |
1089 | ( | |
1090 | cd child1 && | |
1091 | git tag testTag && | |
1092 | git push ../child2 testTag && | |
1093 | >file1 && | |
1094 | git add file1 && | |
1095 | git commit -m 'file1' && | |
1096 | git tag $tag_args testTag && | |
1097 | test_must_fail git push ../child2 testTag && | |
1098 | git push --force ../child2 testTag && | |
1099 | git tag $tag_args testTag HEAD~ && | |
1100 | test_must_fail git push ../child2 testTag && | |
1101 | git push --force ../child2 testTag && | |
1102 | ||
1103 | # Clobbering without + in refspec needs --force | |
1104 | git tag -f testTag && | |
1105 | test_must_fail git push ../child2 'refs/tags/*:refs/tags/*' && | |
1106 | git push --force ../child2 'refs/tags/*:refs/tags/*' && | |
1107 | ||
1108 | # Clobbering with + in refspec does not need --force | |
1109 | git tag -f testTag HEAD~ && | |
1110 | git push ../child2 '+refs/tags/*:refs/tags/*' && | |
1111 | ||
1112 | # Clobbering with --no-force still obeys + in refspec | |
1113 | git tag -f testTag && | |
1114 | git push --no-force ../child2 '+refs/tags/*:refs/tags/*' && | |
1115 | ||
1116 | # Clobbering with/without --force and 'tag <name>' format | |
1117 | git tag -f testTag HEAD~ && | |
1118 | test_must_fail git push ../child2 tag testTag && | |
1119 | git push --force ../child2 tag testTag | |
1120 | ) | |
1121 | " | |
1122 | } | |
1123 | ||
1124 | test_force_push_tag "lightweight tag" "-f" | |
1125 | test_force_push_tag "annotated tag" "-f -a -m'tag message'" | |
1126 | ||
1127 | test_force_fetch_tag () { | |
1128 | tag_type_description=$1 | |
1129 | tag_args=$2 | |
1130 | ||
1131 | test_expect_success "fetch will not clobber an existing $tag_type_description without --force" " | |
1132 | mk_test testrepo heads/main && | |
1133 | mk_child testrepo child1 && | |
1134 | mk_child testrepo child2 && | |
1135 | ( | |
1136 | cd testrepo && | |
1137 | git tag testTag && | |
1138 | git -C ../child1 fetch origin tag testTag && | |
1139 | >file1 && | |
1140 | git add file1 && | |
1141 | git commit -m 'file1' && | |
1142 | git tag $tag_args testTag && | |
1143 | test_must_fail git -C ../child1 fetch origin tag testTag && | |
1144 | git -C ../child1 fetch origin '+refs/tags/*:refs/tags/*' | |
1145 | ) | |
1146 | " | |
1147 | } | |
1148 | ||
1149 | test_force_fetch_tag "lightweight tag" "-f" | |
1150 | test_force_fetch_tag "annotated tag" "-f -a -m'tag message'" | |
1151 | ||
1152 | test_expect_success 'push --porcelain' ' | |
1153 | mk_empty testrepo && | |
1154 | echo >.git/foo "To testrepo" && | |
1155 | echo >>.git/foo "* refs/heads/main:refs/remotes/origin/main [new reference]" && | |
1156 | echo >>.git/foo "Done" && | |
1157 | git push >.git/bar --porcelain testrepo refs/heads/main:refs/remotes/origin/main && | |
1158 | ( | |
1159 | cd testrepo && | |
1160 | echo "$the_commit commit refs/remotes/origin/main" >expect && | |
1161 | git for-each-ref refs/remotes/origin >actual && | |
1162 | test_cmp expect actual | |
1163 | ) && | |
1164 | test_cmp .git/foo .git/bar | |
1165 | ' | |
1166 | ||
1167 | test_expect_success 'push --porcelain bad url' ' | |
1168 | mk_empty testrepo && | |
1169 | test_must_fail git push >.git/bar --porcelain asdfasdfasd refs/heads/main:refs/remotes/origin/main && | |
1170 | ! grep -q Done .git/bar | |
1171 | ' | |
1172 | ||
1173 | test_expect_success 'push --porcelain rejected' ' | |
1174 | mk_empty testrepo && | |
1175 | git push testrepo refs/heads/main:refs/remotes/origin/main && | |
1176 | (cd testrepo && | |
1177 | git reset --hard origin/main^ && | |
1178 | git config receive.denyCurrentBranch true) && | |
1179 | ||
1180 | echo >.git/foo "To testrepo" && | |
1181 | echo >>.git/foo "! refs/heads/main:refs/heads/main [remote rejected] (branch is currently checked out)" && | |
1182 | echo >>.git/foo "Done" && | |
1183 | ||
1184 | test_must_fail git push >.git/bar --porcelain testrepo refs/heads/main:refs/heads/main && | |
1185 | test_cmp .git/foo .git/bar | |
1186 | ' | |
1187 | ||
1188 | test_expect_success 'push --porcelain --dry-run rejected' ' | |
1189 | mk_empty testrepo && | |
1190 | git push testrepo refs/heads/main:refs/remotes/origin/main && | |
1191 | (cd testrepo && | |
1192 | git reset --hard origin/main && | |
1193 | git config receive.denyCurrentBranch true) && | |
1194 | ||
1195 | echo >.git/foo "To testrepo" && | |
1196 | echo >>.git/foo "! refs/heads/main^:refs/heads/main [rejected] (non-fast-forward)" && | |
1197 | echo >>.git/foo "Done" && | |
1198 | ||
1199 | test_must_fail git push >.git/bar --porcelain --dry-run testrepo refs/heads/main^:refs/heads/main && | |
1200 | test_cmp .git/foo .git/bar | |
1201 | ' | |
1202 | ||
1203 | test_expect_success 'push --prune' ' | |
1204 | mk_test testrepo heads/main heads/second heads/foo heads/bar && | |
1205 | git push --prune testrepo : && | |
1206 | check_push_result testrepo $the_commit heads/main && | |
1207 | check_push_result testrepo $the_first_commit heads/second && | |
1208 | ! check_push_result testrepo $the_first_commit heads/foo heads/bar | |
1209 | ' | |
1210 | ||
1211 | test_expect_success 'push --prune refspec' ' | |
1212 | mk_test testrepo tmp/main tmp/second tmp/foo tmp/bar && | |
1213 | git push --prune testrepo "refs/heads/*:refs/tmp/*" && | |
1214 | check_push_result testrepo $the_commit tmp/main && | |
1215 | check_push_result testrepo $the_first_commit tmp/second && | |
1216 | ! check_push_result testrepo $the_first_commit tmp/foo tmp/bar | |
1217 | ' | |
1218 | ||
1219 | for configsection in transfer receive | |
1220 | do | |
1221 | test_expect_success "push to update a ref hidden by $configsection.hiderefs" ' | |
1222 | mk_test testrepo heads/main hidden/one hidden/two hidden/three && | |
1223 | ( | |
1224 | cd testrepo && | |
1225 | git config $configsection.hiderefs refs/hidden | |
1226 | ) && | |
1227 | ||
1228 | # push to unhidden ref succeeds normally | |
1229 | git push testrepo main:refs/heads/main && | |
1230 | check_push_result testrepo $the_commit heads/main && | |
1231 | ||
1232 | # push to update a hidden ref should fail | |
1233 | test_must_fail git push testrepo main:refs/hidden/one && | |
1234 | check_push_result testrepo $the_first_commit hidden/one && | |
1235 | ||
1236 | # push to delete a hidden ref should fail | |
1237 | test_must_fail git push testrepo :refs/hidden/two && | |
1238 | check_push_result testrepo $the_first_commit hidden/two && | |
1239 | ||
1240 | # idempotent push to update a hidden ref should fail | |
1241 | test_must_fail git push testrepo $the_first_commit:refs/hidden/three && | |
1242 | check_push_result testrepo $the_first_commit hidden/three | |
1243 | ' | |
1244 | done | |
1245 | ||
1246 | test_expect_success 'fetch exact SHA1' ' | |
1247 | mk_test testrepo heads/main hidden/one && | |
1248 | git push testrepo main:refs/hidden/one && | |
1249 | ( | |
1250 | cd testrepo && | |
1251 | git config transfer.hiderefs refs/hidden | |
1252 | ) && | |
1253 | check_push_result testrepo $the_commit hidden/one && | |
1254 | ||
1255 | mk_child testrepo child && | |
1256 | ( | |
1257 | cd child && | |
1258 | ||
1259 | # make sure $the_commit does not exist here | |
1260 | git repack -a -d && | |
1261 | git prune && | |
1262 | test_must_fail git cat-file -t $the_commit && | |
1263 | ||
1264 | # Some protocol versions (e.g. 2) support fetching | |
1265 | # unadvertised objects, so restrict this test to v0. | |
1266 | ||
1267 | # fetching the hidden object should fail by default | |
1268 | test_must_fail env GIT_TEST_PROTOCOL_VERSION=0 \ | |
1269 | git fetch -v ../testrepo $the_commit:refs/heads/copy 2>err && | |
1270 | test_i18ngrep "Server does not allow request for unadvertised object" err && | |
1271 | test_must_fail git rev-parse --verify refs/heads/copy && | |
1272 | ||
1273 | # the server side can allow it to succeed | |
1274 | ( | |
1275 | cd ../testrepo && | |
1276 | git config uploadpack.allowtipsha1inwant true | |
1277 | ) && | |
1278 | ||
1279 | git fetch -v ../testrepo $the_commit:refs/heads/copy main:refs/heads/extra && | |
1280 | cat >expect <<-EOF && | |
1281 | $the_commit | |
1282 | $the_first_commit | |
1283 | EOF | |
1284 | { | |
1285 | git rev-parse --verify refs/heads/copy && | |
1286 | git rev-parse --verify refs/heads/extra | |
1287 | } >actual && | |
1288 | test_cmp expect actual | |
1289 | ) | |
1290 | ' | |
1291 | ||
1292 | test_expect_success 'fetch exact SHA1 in protocol v2' ' | |
1293 | mk_test testrepo heads/main hidden/one && | |
1294 | git push testrepo main:refs/hidden/one && | |
1295 | git -C testrepo config transfer.hiderefs refs/hidden && | |
1296 | check_push_result testrepo $the_commit hidden/one && | |
1297 | ||
1298 | mk_child testrepo child && | |
1299 | git -C child config protocol.version 2 && | |
1300 | ||
1301 | # make sure $the_commit does not exist here | |
1302 | git -C child repack -a -d && | |
1303 | git -C child prune && | |
1304 | test_must_fail git -C child cat-file -t $the_commit && | |
1305 | ||
1306 | # fetching the hidden object succeeds by default | |
1307 | # NEEDSWORK: should this match the v0 behavior instead? | |
1308 | git -C child fetch -v ../testrepo $the_commit:refs/heads/copy | |
1309 | ' | |
1310 | ||
1311 | for configallowtipsha1inwant in true false | |
1312 | do | |
1313 | test_expect_success "shallow fetch reachable SHA1 (but not a ref), allowtipsha1inwant=$configallowtipsha1inwant" ' | |
1314 | mk_empty testrepo && | |
1315 | ( | |
1316 | cd testrepo && | |
1317 | git config uploadpack.allowtipsha1inwant $configallowtipsha1inwant && | |
1318 | git commit --allow-empty -m foo && | |
1319 | git commit --allow-empty -m bar | |
1320 | ) && | |
1321 | SHA1=$(git --git-dir=testrepo/.git rev-parse HEAD^) && | |
1322 | mk_empty shallow && | |
1323 | ( | |
1324 | cd shallow && | |
1325 | # Some protocol versions (e.g. 2) support fetching | |
1326 | # unadvertised objects, so restrict this test to v0. | |
1327 | test_must_fail env GIT_TEST_PROTOCOL_VERSION=0 \ | |
1328 | git fetch --depth=1 ../testrepo/.git $SHA1 && | |
1329 | git --git-dir=../testrepo/.git config uploadpack.allowreachablesha1inwant true && | |
1330 | git fetch --depth=1 ../testrepo/.git $SHA1 && | |
1331 | git cat-file commit $SHA1 | |
1332 | ) | |
1333 | ' | |
1334 | ||
1335 | test_expect_success "deny fetch unreachable SHA1, allowtipsha1inwant=$configallowtipsha1inwant" ' | |
1336 | mk_empty testrepo && | |
1337 | ( | |
1338 | cd testrepo && | |
1339 | git config uploadpack.allowtipsha1inwant $configallowtipsha1inwant && | |
1340 | git commit --allow-empty -m foo && | |
1341 | git commit --allow-empty -m bar && | |
1342 | git commit --allow-empty -m xyz | |
1343 | ) && | |
1344 | SHA1_1=$(git --git-dir=testrepo/.git rev-parse HEAD^^) && | |
1345 | SHA1_2=$(git --git-dir=testrepo/.git rev-parse HEAD^) && | |
1346 | SHA1_3=$(git --git-dir=testrepo/.git rev-parse HEAD) && | |
1347 | ( | |
1348 | cd testrepo && | |
1349 | git reset --hard $SHA1_2 && | |
1350 | git cat-file commit $SHA1_1 && | |
1351 | git cat-file commit $SHA1_3 | |
1352 | ) && | |
1353 | mk_empty shallow && | |
1354 | ( | |
1355 | cd shallow && | |
1356 | # Some protocol versions (e.g. 2) support fetching | |
1357 | # unadvertised objects, so restrict this test to v0. | |
1358 | test_must_fail env GIT_TEST_PROTOCOL_VERSION=0 \ | |
1359 | git fetch ../testrepo/.git $SHA1_3 && | |
1360 | test_must_fail env GIT_TEST_PROTOCOL_VERSION=0 \ | |
1361 | git fetch ../testrepo/.git $SHA1_1 && | |
1362 | git --git-dir=../testrepo/.git config uploadpack.allowreachablesha1inwant true && | |
1363 | git fetch ../testrepo/.git $SHA1_1 && | |
1364 | git cat-file commit $SHA1_1 && | |
1365 | test_must_fail git cat-file commit $SHA1_2 && | |
1366 | git fetch ../testrepo/.git $SHA1_2 && | |
1367 | git cat-file commit $SHA1_2 && | |
1368 | test_must_fail env GIT_TEST_PROTOCOL_VERSION=0 \ | |
1369 | git fetch ../testrepo/.git $SHA1_3 2>err && | |
1370 | # ideally we would insist this be on a "remote error:" | |
1371 | # line, but it is racy; see the commit message | |
1372 | test_i18ngrep "not our ref.*$SHA1_3\$" err | |
1373 | ) | |
1374 | ' | |
1375 | done | |
1376 | ||
1377 | test_expect_success 'fetch follows tags by default' ' | |
1378 | mk_test testrepo heads/main && | |
1379 | test_when_finished "rm -rf src" && | |
1380 | git init src && | |
1381 | ( | |
1382 | cd src && | |
1383 | git pull ../testrepo main && | |
1384 | git tag -m "annotated" tag && | |
1385 | git for-each-ref >tmp1 && | |
1386 | sed -n "p; s|refs/heads/main$|refs/remotes/origin/main|p" tmp1 | | |
1387 | sort -k 3 >../expect | |
1388 | ) && | |
1389 | test_when_finished "rm -rf dst" && | |
1390 | git init dst && | |
1391 | ( | |
1392 | cd dst && | |
1393 | git remote add origin ../src && | |
1394 | git config branch.main.remote origin && | |
1395 | git config branch.main.merge refs/heads/main && | |
1396 | git pull && | |
1397 | git for-each-ref >../actual | |
1398 | ) && | |
1399 | test_cmp expect actual | |
1400 | ' | |
1401 | ||
1402 | test_expect_success 'peeled advertisements are not considered ref tips' ' | |
1403 | mk_empty testrepo && | |
1404 | git -C testrepo commit --allow-empty -m one && | |
1405 | git -C testrepo commit --allow-empty -m two && | |
1406 | git -C testrepo tag -m foo mytag HEAD^ && | |
1407 | oid=$(git -C testrepo rev-parse mytag^{commit}) && | |
1408 | test_must_fail env GIT_TEST_PROTOCOL_VERSION=0 \ | |
1409 | git fetch testrepo $oid 2>err && | |
1410 | test_i18ngrep "Server does not allow request for unadvertised object" err | |
1411 | ' | |
1412 | ||
1413 | test_expect_success 'pushing a specific ref applies remote.$name.push as refmap' ' | |
1414 | mk_test testrepo heads/main && | |
1415 | test_when_finished "rm -rf src" && | |
1416 | git init src && | |
1417 | test_when_finished "rm -rf dst" && | |
1418 | git init --bare dst && | |
1419 | ( | |
1420 | cd src && | |
1421 | git pull ../testrepo main && | |
1422 | git branch next && | |
1423 | git config remote.dst.url ../dst && | |
1424 | git config remote.dst.push "+refs/heads/*:refs/remotes/src/*" && | |
1425 | git push dst main && | |
1426 | git show-ref refs/heads/main | | |
1427 | sed -e "s|refs/heads/|refs/remotes/src/|" >../dst/expect | |
1428 | ) && | |
1429 | ( | |
1430 | cd dst && | |
1431 | test_must_fail git show-ref refs/heads/next && | |
1432 | test_must_fail git show-ref refs/heads/main && | |
1433 | git show-ref refs/remotes/src/main >actual | |
1434 | ) && | |
1435 | test_cmp dst/expect dst/actual | |
1436 | ' | |
1437 | ||
1438 | test_expect_success 'with no remote.$name.push, it is not used as refmap' ' | |
1439 | mk_test testrepo heads/main && | |
1440 | test_when_finished "rm -rf src" && | |
1441 | git init src && | |
1442 | test_when_finished "rm -rf dst" && | |
1443 | git init --bare dst && | |
1444 | ( | |
1445 | cd src && | |
1446 | git pull ../testrepo main && | |
1447 | git branch next && | |
1448 | git config remote.dst.url ../dst && | |
1449 | git config push.default matching && | |
1450 | git push dst main && | |
1451 | git show-ref refs/heads/main >../dst/expect | |
1452 | ) && | |
1453 | ( | |
1454 | cd dst && | |
1455 | test_must_fail git show-ref refs/heads/next && | |
1456 | git show-ref refs/heads/main >actual | |
1457 | ) && | |
1458 | test_cmp dst/expect dst/actual | |
1459 | ' | |
1460 | ||
1461 | test_expect_success 'with no remote.$name.push, upstream mapping is used' ' | |
1462 | mk_test testrepo heads/main && | |
1463 | test_when_finished "rm -rf src" && | |
1464 | git init src && | |
1465 | test_when_finished "rm -rf dst" && | |
1466 | git init --bare dst && | |
1467 | ( | |
1468 | cd src && | |
1469 | git pull ../testrepo main && | |
1470 | git branch next && | |
1471 | git config remote.dst.url ../dst && | |
1472 | git config remote.dst.fetch "+refs/heads/*:refs/remotes/dst/*" && | |
1473 | git config push.default upstream && | |
1474 | ||
1475 | git config branch.main.merge refs/heads/trunk && | |
1476 | git config branch.main.remote dst && | |
1477 | ||
1478 | git push dst main && | |
1479 | git show-ref refs/heads/main | | |
1480 | sed -e "s|refs/heads/main|refs/heads/trunk|" >../dst/expect | |
1481 | ) && | |
1482 | ( | |
1483 | cd dst && | |
1484 | test_must_fail git show-ref refs/heads/main && | |
1485 | test_must_fail git show-ref refs/heads/next && | |
1486 | git show-ref refs/heads/trunk >actual | |
1487 | ) && | |
1488 | test_cmp dst/expect dst/actual | |
1489 | ' | |
1490 | ||
1491 | test_expect_success 'push does not follow tags by default' ' | |
1492 | mk_test testrepo heads/main && | |
1493 | test_when_finished "rm -rf src" && | |
1494 | git init src && | |
1495 | test_when_finished "rm -rf dst" && | |
1496 | git init --bare dst && | |
1497 | ( | |
1498 | cd src && | |
1499 | git pull ../testrepo main && | |
1500 | git tag -m "annotated" tag && | |
1501 | git checkout -b another && | |
1502 | git commit --allow-empty -m "future commit" && | |
1503 | git tag -m "future" future && | |
1504 | git checkout main && | |
1505 | git for-each-ref refs/heads/main >../expect && | |
1506 | git push ../dst main | |
1507 | ) && | |
1508 | ( | |
1509 | cd dst && | |
1510 | git for-each-ref >../actual | |
1511 | ) && | |
1512 | test_cmp expect actual | |
1513 | ' | |
1514 | ||
1515 | test_expect_success 'push --follow-tags only pushes relevant tags' ' | |
1516 | mk_test testrepo heads/main && | |
1517 | test_when_finished "rm -rf src" && | |
1518 | git init src && | |
1519 | test_when_finished "rm -rf dst" && | |
1520 | git init --bare dst && | |
1521 | ( | |
1522 | cd src && | |
1523 | git pull ../testrepo main && | |
1524 | git tag -m "annotated" tag && | |
1525 | git checkout -b another && | |
1526 | git commit --allow-empty -m "future commit" && | |
1527 | git tag -m "future" future && | |
1528 | git checkout main && | |
1529 | git for-each-ref refs/heads/main refs/tags/tag >../expect && | |
1530 | git push --follow-tags ../dst main | |
1531 | ) && | |
1532 | ( | |
1533 | cd dst && | |
1534 | git for-each-ref >../actual | |
1535 | ) && | |
1536 | test_cmp expect actual | |
1537 | ' | |
1538 | ||
1539 | test_expect_success 'push --no-thin must produce non-thin pack' ' | |
1540 | cat >>path1 <<\EOF && | |
1541 | keep base version of path1 big enough, compared to the new changes | |
1542 | later, in order to pass size heuristics in | |
1543 | builtin/pack-objects.c:try_delta() | |
1544 | EOF | |
1545 | git commit -am initial && | |
1546 | git init no-thin && | |
1547 | git --git-dir=no-thin/.git config receive.unpacklimit 0 && | |
1548 | git push no-thin/.git refs/heads/main:refs/heads/foo && | |
1549 | echo modified >> path1 && | |
1550 | git commit -am modified && | |
1551 | git repack -adf && | |
1552 | rcvpck="git receive-pack --reject-thin-pack-for-testing" && | |
1553 | git push --no-thin --receive-pack="$rcvpck" no-thin/.git refs/heads/main:refs/heads/foo | |
1554 | ' | |
1555 | ||
1556 | test_expect_success 'pushing a tag pushes the tagged object' ' | |
1557 | blob=$(echo unreferenced | git hash-object -w --stdin) && | |
1558 | git tag -m foo tag-of-blob $blob && | |
1559 | test_when_finished "rm -rf dst.git" && | |
1560 | git init --bare dst.git && | |
1561 | git push dst.git tag-of-blob && | |
1562 | # the receiving index-pack should have noticed | |
1563 | # any problems, but we double check | |
1564 | echo unreferenced >expect && | |
1565 | git --git-dir=dst.git cat-file blob tag-of-blob >actual && | |
1566 | test_cmp expect actual | |
1567 | ' | |
1568 | ||
1569 | test_expect_success 'push into bare respects core.logallrefupdates' ' | |
1570 | test_when_finished "rm -rf dst.git" && | |
1571 | git init --bare dst.git && | |
1572 | git -C dst.git config core.logallrefupdates true && | |
1573 | ||
1574 | # double push to test both with and without | |
1575 | # the actual pack transfer | |
1576 | git push dst.git main:one && | |
1577 | echo "one@{0} push" >expect && | |
1578 | git -C dst.git log -g --format="%gd %gs" one >actual && | |
1579 | test_cmp expect actual && | |
1580 | ||
1581 | git push dst.git main:two && | |
1582 | echo "two@{0} push" >expect && | |
1583 | git -C dst.git log -g --format="%gd %gs" two >actual && | |
1584 | test_cmp expect actual | |
1585 | ' | |
1586 | ||
1587 | test_expect_success 'fetch into bare respects core.logallrefupdates' ' | |
1588 | test_when_finished "rm -rf dst.git" && | |
1589 | git init --bare dst.git && | |
1590 | ( | |
1591 | cd dst.git && | |
1592 | git config core.logallrefupdates true && | |
1593 | ||
1594 | # as above, we double-fetch to test both | |
1595 | # with and without pack transfer | |
1596 | git fetch .. main:one && | |
1597 | echo "one@{0} fetch .. main:one: storing head" >expect && | |
1598 | git log -g --format="%gd %gs" one >actual && | |
1599 | test_cmp expect actual && | |
1600 | ||
1601 | git fetch .. main:two && | |
1602 | echo "two@{0} fetch .. main:two: storing head" >expect && | |
1603 | git log -g --format="%gd %gs" two >actual && | |
1604 | test_cmp expect actual | |
1605 | ) | |
1606 | ' | |
1607 | ||
1608 | test_expect_success 'receive.denyCurrentBranch = updateInstead' ' | |
1609 | mk_empty testrepo && | |
1610 | git push testrepo main && | |
1611 | ( | |
1612 | cd testrepo && | |
1613 | git reset --hard && | |
1614 | git config receive.denyCurrentBranch updateInstead | |
1615 | ) && | |
1616 | test_commit third path2 && | |
1617 | ||
1618 | # Try pushing into a repository with pristine working tree | |
1619 | git push testrepo main && | |
1620 | ( | |
1621 | cd testrepo && | |
1622 | git update-index -q --refresh && | |
1623 | git diff-files --quiet -- && | |
1624 | git diff-index --quiet --cached HEAD -- && | |
1625 | test third = "$(cat path2)" && | |
1626 | test $(git -C .. rev-parse HEAD) = $(git rev-parse HEAD) | |
1627 | ) && | |
1628 | ||
1629 | # Try pushing into a repository with working tree needing a refresh | |
1630 | ( | |
1631 | cd testrepo && | |
1632 | git reset --hard HEAD^ && | |
1633 | test $(git -C .. rev-parse HEAD^) = $(git rev-parse HEAD) && | |
1634 | test-tool chmtime +100 path1 | |
1635 | ) && | |
1636 | git push testrepo main && | |
1637 | ( | |
1638 | cd testrepo && | |
1639 | git update-index -q --refresh && | |
1640 | git diff-files --quiet -- && | |
1641 | git diff-index --quiet --cached HEAD -- && | |
1642 | test_cmp ../path1 path1 && | |
1643 | test third = "$(cat path2)" && | |
1644 | test $(git -C .. rev-parse HEAD) = $(git rev-parse HEAD) | |
1645 | ) && | |
1646 | ||
1647 | # Update what is to be pushed | |
1648 | test_commit fourth path2 && | |
1649 | ||
1650 | # Try pushing into a repository with a dirty working tree | |
1651 | # (1) the working tree updated | |
1652 | ( | |
1653 | cd testrepo && | |
1654 | echo changed >path1 | |
1655 | ) && | |
1656 | test_must_fail git push testrepo main && | |
1657 | ( | |
1658 | cd testrepo && | |
1659 | test $(git -C .. rev-parse HEAD^) = $(git rev-parse HEAD) && | |
1660 | git diff --quiet --cached && | |
1661 | test changed = "$(cat path1)" | |
1662 | ) && | |
1663 | ||
1664 | # (2) the index updated | |
1665 | ( | |
1666 | cd testrepo && | |
1667 | echo changed >path1 && | |
1668 | git add path1 | |
1669 | ) && | |
1670 | test_must_fail git push testrepo main && | |
1671 | ( | |
1672 | cd testrepo && | |
1673 | test $(git -C .. rev-parse HEAD^) = $(git rev-parse HEAD) && | |
1674 | git diff --quiet && | |
1675 | test changed = "$(cat path1)" | |
1676 | ) && | |
1677 | ||
1678 | # Introduce a new file in the update | |
1679 | test_commit fifth path3 && | |
1680 | ||
1681 | # (3) the working tree has an untracked file that would interfere | |
1682 | ( | |
1683 | cd testrepo && | |
1684 | git reset --hard && | |
1685 | echo changed >path3 | |
1686 | ) && | |
1687 | test_must_fail git push testrepo main && | |
1688 | ( | |
1689 | cd testrepo && | |
1690 | test $(git -C .. rev-parse HEAD^^) = $(git rev-parse HEAD) && | |
1691 | git diff --quiet && | |
1692 | git diff --quiet --cached && | |
1693 | test changed = "$(cat path3)" | |
1694 | ) && | |
1695 | ||
1696 | # (4) the target changes to what gets pushed but it still is a change | |
1697 | ( | |
1698 | cd testrepo && | |
1699 | git reset --hard && | |
1700 | echo fifth >path3 && | |
1701 | git add path3 | |
1702 | ) && | |
1703 | test_must_fail git push testrepo main && | |
1704 | ( | |
1705 | cd testrepo && | |
1706 | test $(git -C .. rev-parse HEAD^^) = $(git rev-parse HEAD) && | |
1707 | git diff --quiet && | |
1708 | test fifth = "$(cat path3)" | |
1709 | ) && | |
1710 | ||
1711 | # (5) push into void | |
1712 | test_when_finished "rm -rf void" && | |
1713 | git init void && | |
1714 | ( | |
1715 | cd void && | |
1716 | git config receive.denyCurrentBranch updateInstead | |
1717 | ) && | |
1718 | git push void main && | |
1719 | ( | |
1720 | cd void && | |
1721 | test $(git -C .. rev-parse main) = $(git rev-parse HEAD) && | |
1722 | git diff --quiet && | |
1723 | git diff --cached --quiet | |
1724 | ) && | |
1725 | ||
1726 | # (6) updateInstead intervened by fast-forward check | |
1727 | test_must_fail git push void main^:main && | |
1728 | test $(git -C void rev-parse HEAD) = $(git rev-parse main) && | |
1729 | git -C void diff --quiet && | |
1730 | git -C void diff --cached --quiet | |
1731 | ' | |
1732 | ||
1733 | test_expect_success 'updateInstead with push-to-checkout hook' ' | |
1734 | test_when_finished "rm -rf testrepo" && | |
1735 | git init testrepo && | |
1736 | git -C testrepo pull .. main && | |
1737 | git -C testrepo reset --hard HEAD^^ && | |
1738 | git -C testrepo tag initial && | |
1739 | git -C testrepo config receive.denyCurrentBranch updateInstead && | |
1740 | test_hook -C testrepo push-to-checkout <<-\EOF && | |
1741 | echo >&2 updating from $(git rev-parse HEAD) | |
1742 | echo >&2 updating to "$1" | |
1743 | ||
1744 | git update-index -q --refresh && | |
1745 | git read-tree -u -m HEAD "$1" || { | |
1746 | status=$? | |
1747 | echo >&2 read-tree failed | |
1748 | exit $status | |
1749 | } | |
1750 | EOF | |
1751 | ||
1752 | # Try pushing into a pristine | |
1753 | git push testrepo main && | |
1754 | ( | |
1755 | cd testrepo && | |
1756 | git diff --quiet && | |
1757 | git diff HEAD --quiet && | |
1758 | test $(git -C .. rev-parse HEAD) = $(git rev-parse HEAD) | |
1759 | ) && | |
1760 | ||
1761 | # Try pushing into a repository with conflicting change | |
1762 | ( | |
1763 | cd testrepo && | |
1764 | git reset --hard initial && | |
1765 | echo conflicting >path2 | |
1766 | ) && | |
1767 | test_must_fail git push testrepo main && | |
1768 | ( | |
1769 | cd testrepo && | |
1770 | test $(git rev-parse initial) = $(git rev-parse HEAD) && | |
1771 | test conflicting = "$(cat path2)" && | |
1772 | git diff-index --quiet --cached HEAD | |
1773 | ) && | |
1774 | ||
1775 | # Try pushing into a repository with unrelated change | |
1776 | ( | |
1777 | cd testrepo && | |
1778 | git reset --hard initial && | |
1779 | echo unrelated >path1 && | |
1780 | echo irrelevant >path5 && | |
1781 | git add path5 | |
1782 | ) && | |
1783 | git push testrepo main && | |
1784 | ( | |
1785 | cd testrepo && | |
1786 | test "$(cat path1)" = unrelated && | |
1787 | test "$(cat path5)" = irrelevant && | |
1788 | test "$(git diff --name-only --cached HEAD)" = path5 && | |
1789 | test $(git -C .. rev-parse HEAD) = $(git rev-parse HEAD) | |
1790 | ) && | |
1791 | ||
1792 | # push into void | |
1793 | test_when_finished "rm -rf void" && | |
1794 | git init void && | |
1795 | git -C void config receive.denyCurrentBranch updateInstead && | |
1796 | test_hook -C void push-to-checkout <<-\EOF && | |
1797 | if git rev-parse --quiet --verify HEAD | |
1798 | then | |
1799 | has_head=yes | |
1800 | echo >&2 updating from $(git rev-parse HEAD) | |
1801 | else | |
1802 | has_head=no | |
1803 | echo >&2 pushing into void | |
1804 | fi | |
1805 | echo >&2 updating to "$1" | |
1806 | ||
1807 | git update-index -q --refresh && | |
1808 | case "$has_head" in | |
1809 | yes) | |
1810 | git read-tree -u -m HEAD "$1" ;; | |
1811 | no) | |
1812 | git read-tree -u -m "$1" ;; | |
1813 | esac || { | |
1814 | status=$? | |
1815 | echo >&2 read-tree failed | |
1816 | exit $status | |
1817 | } | |
1818 | EOF | |
1819 | ||
1820 | git push void main && | |
1821 | ( | |
1822 | cd void && | |
1823 | git diff --quiet && | |
1824 | git diff --cached --quiet && | |
1825 | test $(git -C .. rev-parse HEAD) = $(git rev-parse HEAD) | |
1826 | ) | |
1827 | ' | |
1828 | ||
1829 | test_expect_success 'denyCurrentBranch and worktrees' ' | |
1830 | git worktree add new-wt && | |
1831 | git clone . cloned && | |
1832 | test_commit -C cloned first && | |
1833 | test_config receive.denyCurrentBranch refuse && | |
1834 | test_must_fail git -C cloned push origin HEAD:new-wt && | |
1835 | test_config receive.denyCurrentBranch updateInstead && | |
1836 | git -C cloned push origin HEAD:new-wt && | |
1837 | test_path_exists new-wt/first.t && | |
1838 | test_must_fail git -C cloned push --delete origin new-wt | |
1839 | ' | |
1840 | ||
1841 | test_expect_success 'denyCurrentBranch and bare repository worktrees' ' | |
1842 | test_when_finished "rm -fr bare.git" && | |
1843 | git clone --bare . bare.git && | |
1844 | git -C bare.git worktree add wt && | |
1845 | test_commit grape && | |
1846 | git -C bare.git config receive.denyCurrentBranch refuse && | |
1847 | test_must_fail git push bare.git HEAD:wt && | |
1848 | git -C bare.git config receive.denyCurrentBranch updateInstead && | |
1849 | git push bare.git HEAD:wt && | |
1850 | test_path_exists bare.git/wt/grape.t && | |
1851 | test_must_fail git push --delete bare.git wt | |
1852 | ' | |
1853 | ||
1854 | test_expect_success 'refuse fetch to current branch of worktree' ' | |
1855 | test_when_finished "git worktree remove --force wt && git branch -D wt" && | |
1856 | git worktree add wt && | |
1857 | test_commit apple && | |
1858 | test_must_fail git fetch . HEAD:wt && | |
1859 | git fetch -u . HEAD:wt | |
1860 | ' | |
1861 | ||
1862 | test_expect_success 'refuse fetch to current branch of bare repository worktree' ' | |
1863 | test_when_finished "rm -fr bare.git" && | |
1864 | git clone --bare . bare.git && | |
1865 | git -C bare.git worktree add wt && | |
1866 | test_commit banana && | |
1867 | test_must_fail git -C bare.git fetch .. HEAD:wt && | |
1868 | git -C bare.git fetch -u .. HEAD:wt | |
1869 | ' | |
1870 | ||
1871 | test_expect_success 'refuse to push a hidden ref, and make sure do not pollute the repository' ' | |
1872 | mk_empty testrepo && | |
1873 | git -C testrepo config receive.hiderefs refs/hidden && | |
1874 | git -C testrepo config receive.unpackLimit 1 && | |
1875 | test_must_fail git push testrepo HEAD:refs/hidden/foo && | |
1876 | test_dir_is_empty testrepo/.git/objects/pack | |
1877 | ' | |
1878 | ||
1879 | test_expect_success 'push with config push.useBitmaps' ' | |
1880 | mk_test testrepo heads/main && | |
1881 | git checkout main && | |
1882 | test_unconfig push.useBitmaps && | |
1883 | GIT_TRACE2_EVENT="$PWD/default" \ | |
1884 | git push --quiet testrepo main:test && | |
1885 | test_subcommand git pack-objects --all-progress-implied --revs --stdout \ | |
1886 | --thin --delta-base-offset -q <default && | |
1887 | ||
1888 | test_config push.useBitmaps true && | |
1889 | GIT_TRACE2_EVENT="$PWD/true" \ | |
1890 | git push --quiet testrepo main:test2 && | |
1891 | test_subcommand git pack-objects --all-progress-implied --revs --stdout \ | |
1892 | --thin --delta-base-offset -q <true && | |
1893 | ||
1894 | test_config push.useBitmaps false && | |
1895 | GIT_TRACE2_EVENT="$PWD/false" \ | |
1896 | git push --quiet testrepo main:test3 && | |
1897 | test_subcommand git pack-objects --all-progress-implied --revs --stdout \ | |
1898 | --thin --delta-base-offset -q --no-use-bitmap-index <false | |
1899 | ' | |
1900 | ||
1901 | test_done |