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