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