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