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