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