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