]>
Commit | Line | Data |
---|---|---|
7be1d62c JH |
1 | #!/bin/sh |
2 | # Copyright (c) 2006, Junio C Hamano. | |
3 | ||
4 | test_description='Per branch config variables affects "git fetch". | |
5 | ||
6 | ' | |
7 | ||
8 | . ./test-lib.sh | |
e8a8e7ff | 9 | . "$TEST_DIRECTORY"/lib-bundle.sh |
7be1d62c | 10 | |
a9d32be4 | 11 | D=$(pwd) |
7be1d62c JH |
12 | |
13 | test_expect_success setup ' | |
14 | echo >file original && | |
15 | git add file && | |
83ecf26e JS |
16 | git commit -a -m original && |
17 | git branch -M main | |
18 | ' | |
7be1d62c JH |
19 | |
20 | test_expect_success "clone and setup child repos" ' | |
21 | git clone . one && | |
18a82692 JN |
22 | ( |
23 | cd one && | |
24 | echo >file updated by one && | |
25 | git commit -a -m "updated by one" | |
fd4ec4f2 | 26 | ) && |
7be1d62c | 27 | git clone . two && |
18a82692 JN |
28 | ( |
29 | cd two && | |
83ecf26e | 30 | git config branch.main.remote one && |
18a82692 | 31 | git config remote.one.url ../one/.git/ && |
83ecf26e | 32 | git config remote.one.fetch refs/heads/main:refs/heads/one |
fd4ec4f2 | 33 | ) && |
6cc7c36d | 34 | git clone . three && |
18a82692 JN |
35 | ( |
36 | cd three && | |
83ecf26e JS |
37 | git config branch.main.remote two && |
38 | git config branch.main.merge refs/heads/one && | |
18a82692 | 39 | mkdir -p .git/remotes && |
020b813f ES |
40 | cat >.git/remotes/two <<-\EOF |
41 | URL: ../two/.git/ | |
42 | Pull: refs/heads/main:refs/heads/two | |
43 | Pull: refs/heads/one:refs/heads/one | |
44 | EOF | |
fd4ec4f2 | 45 | ) && |
9a7bbd1d JK |
46 | git clone . bundle && |
47 | git clone . seven | |
7be1d62c JH |
48 | ' |
49 | ||
50 | test_expect_success "fetch test" ' | |
51 | cd "$D" && | |
52 | echo >file updated by origin && | |
53 | git commit -a -m "updated by origin" && | |
54 | cd two && | |
55 | git fetch && | |
cbc5cf7c | 56 | git rev-parse --verify refs/heads/one && |
a9d32be4 | 57 | mine=$(git rev-parse refs/heads/one) && |
83ecf26e | 58 | his=$(cd ../one && git rev-parse refs/heads/main) && |
7be1d62c JH |
59 | test "z$mine" = "z$his" |
60 | ' | |
61 | ||
6cc7c36d SB |
62 | test_expect_success "fetch test for-merge" ' |
63 | cd "$D" && | |
64 | cd three && | |
65 | git fetch && | |
cbc5cf7c DT |
66 | git rev-parse --verify refs/heads/two && |
67 | git rev-parse --verify refs/heads/one && | |
83ecf26e | 68 | main_in_two=$(cd ../two && git rev-parse main) && |
a9d32be4 | 69 | one_in_two=$(cd ../two && git rev-parse one) && |
6cc7c36d | 70 | { |
7abcbcb7 | 71 | echo "$one_in_two " && |
83ecf26e | 72 | echo "$main_in_two not-for-merge" |
6cc7c36d SB |
73 | } >expected && |
74 | cut -f -2 .git/FETCH_HEAD >actual && | |
4fdf71be | 75 | test_cmp expected actual' |
6cc7c36d | 76 | |
43a8a04a CMN |
77 | test_expect_success 'fetch --prune on its own works as expected' ' |
78 | cd "$D" && | |
79 | git clone . prune && | |
80 | cd prune && | |
83ecf26e | 81 | git update-ref refs/remotes/origin/extrabranch main && |
43a8a04a CMN |
82 | |
83 | git fetch --prune origin && | |
84 | test_must_fail git rev-parse origin/extrabranch | |
85 | ' | |
86 | ||
ed43de6e | 87 | test_expect_success 'fetch --prune with a branch name keeps branches' ' |
43a8a04a CMN |
88 | cd "$D" && |
89 | git clone . prune-branch && | |
90 | cd prune-branch && | |
83ecf26e | 91 | git update-ref refs/remotes/origin/extrabranch main && |
43a8a04a | 92 | |
83ecf26e | 93 | git fetch --prune origin main && |
43a8a04a CMN |
94 | git rev-parse origin/extrabranch |
95 | ' | |
96 | ||
ed43de6e | 97 | test_expect_success 'fetch --prune with a namespace keeps other namespaces' ' |
43a8a04a CMN |
98 | cd "$D" && |
99 | git clone . prune-namespace && | |
100 | cd prune-namespace && | |
101 | ||
102 | git fetch --prune origin refs/heads/a/*:refs/remotes/origin/a/* && | |
83ecf26e | 103 | git rev-parse origin/main |
43a8a04a CMN |
104 | ' |
105 | ||
e6f63712 | 106 | test_expect_success 'fetch --prune handles overlapping refspecs' ' |
f377e7a3 | 107 | cd "$D" && |
83ecf26e | 108 | git update-ref refs/pull/42/head main && |
f377e7a3 CMN |
109 | git clone . prune-overlapping && |
110 | cd prune-overlapping && | |
111 | git config --add remote.origin.fetch refs/pull/*/head:refs/remotes/origin/pr/* && | |
112 | ||
113 | git fetch --prune origin && | |
83ecf26e | 114 | git rev-parse origin/main && |
f377e7a3 CMN |
115 | git rev-parse origin/pr/42 && |
116 | ||
8fb26872 | 117 | git config --unset-all remote.origin.fetch && |
f377e7a3 CMN |
118 | git config remote.origin.fetch refs/pull/*/head:refs/remotes/origin/pr/* && |
119 | git config --add remote.origin.fetch refs/heads/*:refs/remotes/origin/* && | |
120 | ||
121 | git fetch --prune origin && | |
83ecf26e | 122 | git rev-parse origin/main && |
f377e7a3 CMN |
123 | git rev-parse origin/pr/42 |
124 | ' | |
125 | ||
0838bf47 | 126 | test_expect_success 'fetch --prune --tags prunes branches but not tags' ' |
43a8a04a CMN |
127 | cd "$D" && |
128 | git clone . prune-tags && | |
129 | cd prune-tags && | |
83ecf26e | 130 | git tag sometag main && |
68a304d5 MH |
131 | # Create what looks like a remote-tracking branch from an earlier |
132 | # fetch that has since been deleted from the remote: | |
83ecf26e | 133 | git update-ref refs/remotes/origin/fake-remote main && |
43a8a04a CMN |
134 | |
135 | git fetch --prune --tags origin && | |
83ecf26e | 136 | git rev-parse origin/main && |
c5a84e92 | 137 | test_must_fail git rev-parse origin/fake-remote && |
0838bf47 | 138 | git rev-parse sometag |
43a8a04a CMN |
139 | ' |
140 | ||
0838bf47 | 141 | test_expect_success 'fetch --prune --tags with branch does not prune other things' ' |
43a8a04a CMN |
142 | cd "$D" && |
143 | git clone . prune-tags-branch && | |
144 | cd prune-tags-branch && | |
83ecf26e JS |
145 | git tag sometag main && |
146 | git update-ref refs/remotes/origin/extrabranch main && | |
43a8a04a | 147 | |
83ecf26e | 148 | git fetch --prune --tags origin main && |
c5a84e92 | 149 | git rev-parse origin/extrabranch && |
0838bf47 | 150 | git rev-parse sometag |
c5a84e92 MH |
151 | ' |
152 | ||
153 | test_expect_success 'fetch --prune --tags with refspec prunes based on refspec' ' | |
154 | cd "$D" && | |
155 | git clone . prune-tags-refspec && | |
156 | cd prune-tags-refspec && | |
83ecf26e JS |
157 | git tag sometag main && |
158 | git update-ref refs/remotes/origin/foo/otherbranch main && | |
159 | git update-ref refs/remotes/origin/extrabranch main && | |
c5a84e92 MH |
160 | |
161 | git fetch --prune --tags origin refs/heads/foo/*:refs/remotes/origin/foo/* && | |
162 | test_must_fail git rev-parse refs/remotes/origin/foo/otherbranch && | |
163 | git rev-parse origin/extrabranch && | |
0838bf47 | 164 | git rev-parse sometag |
43a8a04a CMN |
165 | ' |
166 | ||
c9e04d90 TG |
167 | test_expect_success REFFILES 'fetch --prune fails to delete branches' ' |
168 | cd "$D" && | |
169 | git clone . prune-fail && | |
170 | cd prune-fail && | |
171 | git update-ref refs/remotes/origin/extrabranch main && | |
172 | : this will prevent --prune from locking packed-refs for deleting refs, but adding loose refs still succeeds && | |
173 | >.git/packed-refs.new && | |
174 | ||
175 | test_must_fail git fetch --prune origin | |
176 | ' | |
177 | ||
c7b190da PS |
178 | test_expect_success 'fetch --atomic works with a single branch' ' |
179 | test_when_finished "rm -rf \"$D\"/atomic" && | |
180 | ||
181 | cd "$D" && | |
182 | git clone . atomic && | |
183 | git branch atomic-branch && | |
184 | oid=$(git rev-parse atomic-branch) && | |
185 | echo "$oid" >expected && | |
186 | ||
187 | git -C atomic fetch --atomic origin && | |
188 | git -C atomic rev-parse origin/atomic-branch >actual && | |
189 | test_cmp expected actual && | |
190 | test $oid = "$(git -C atomic rev-parse --verify FETCH_HEAD)" | |
191 | ' | |
192 | ||
193 | test_expect_success 'fetch --atomic works with multiple branches' ' | |
194 | test_when_finished "rm -rf \"$D\"/atomic" && | |
195 | ||
196 | cd "$D" && | |
197 | git clone . atomic && | |
198 | git branch atomic-branch-1 && | |
199 | git branch atomic-branch-2 && | |
200 | git branch atomic-branch-3 && | |
201 | git rev-parse refs/heads/atomic-branch-1 refs/heads/atomic-branch-2 refs/heads/atomic-branch-3 >actual && | |
202 | ||
203 | git -C atomic fetch --atomic origin && | |
204 | git -C atomic rev-parse refs/remotes/origin/atomic-branch-1 refs/remotes/origin/atomic-branch-2 refs/remotes/origin/atomic-branch-3 >expected && | |
205 | test_cmp expected actual | |
206 | ' | |
207 | ||
208 | test_expect_success 'fetch --atomic works with mixed branches and tags' ' | |
209 | test_when_finished "rm -rf \"$D\"/atomic" && | |
210 | ||
211 | cd "$D" && | |
212 | git clone . atomic && | |
213 | git branch atomic-mixed-branch && | |
214 | git tag atomic-mixed-tag && | |
215 | git rev-parse refs/heads/atomic-mixed-branch refs/tags/atomic-mixed-tag >actual && | |
216 | ||
217 | git -C atomic fetch --tags --atomic origin && | |
218 | git -C atomic rev-parse refs/remotes/origin/atomic-mixed-branch refs/tags/atomic-mixed-tag >expected && | |
219 | test_cmp expected actual | |
220 | ' | |
221 | ||
222 | test_expect_success 'fetch --atomic prunes references' ' | |
223 | test_when_finished "rm -rf \"$D\"/atomic" && | |
224 | ||
225 | cd "$D" && | |
226 | git branch atomic-prune-delete && | |
227 | git clone . atomic && | |
228 | git branch --delete atomic-prune-delete && | |
229 | git branch atomic-prune-create && | |
230 | git rev-parse refs/heads/atomic-prune-create >actual && | |
231 | ||
232 | git -C atomic fetch --prune --atomic origin && | |
233 | test_must_fail git -C atomic rev-parse refs/remotes/origin/atomic-prune-delete && | |
234 | git -C atomic rev-parse refs/remotes/origin/atomic-prune-create >expected && | |
235 | test_cmp expected actual | |
236 | ' | |
237 | ||
238 | test_expect_success 'fetch --atomic aborts with non-fast-forward update' ' | |
239 | test_when_finished "rm -rf \"$D\"/atomic" && | |
240 | ||
241 | cd "$D" && | |
242 | git branch atomic-non-ff && | |
243 | git clone . atomic && | |
244 | git rev-parse HEAD >actual && | |
245 | ||
246 | git branch atomic-new-branch && | |
247 | parent_commit=$(git rev-parse atomic-non-ff~) && | |
248 | git update-ref refs/heads/atomic-non-ff $parent_commit && | |
249 | ||
250 | test_must_fail git -C atomic fetch --atomic origin refs/heads/*:refs/remotes/origin/* && | |
251 | test_must_fail git -C atomic rev-parse refs/remotes/origin/atomic-new-branch && | |
252 | git -C atomic rev-parse refs/remotes/origin/atomic-non-ff >expected && | |
253 | test_cmp expected actual && | |
254 | test_must_be_empty atomic/.git/FETCH_HEAD | |
255 | ' | |
256 | ||
257 | test_expect_success 'fetch --atomic executes a single reference transaction only' ' | |
258 | test_when_finished "rm -rf \"$D\"/atomic" && | |
259 | ||
260 | cd "$D" && | |
261 | git clone . atomic && | |
262 | git branch atomic-hooks-1 && | |
263 | git branch atomic-hooks-2 && | |
264 | head_oid=$(git rev-parse HEAD) && | |
265 | ||
266 | cat >expected <<-EOF && | |
267 | prepared | |
268 | $ZERO_OID $head_oid refs/remotes/origin/atomic-hooks-1 | |
269 | $ZERO_OID $head_oid refs/remotes/origin/atomic-hooks-2 | |
270 | committed | |
271 | $ZERO_OID $head_oid refs/remotes/origin/atomic-hooks-1 | |
272 | $ZERO_OID $head_oid refs/remotes/origin/atomic-hooks-2 | |
273 | EOF | |
274 | ||
275 | rm -f atomic/actual && | |
7da7f63c | 276 | test_hook -C atomic reference-transaction <<-\EOF && |
c7b190da PS |
277 | ( echo "$*" && cat ) >>actual |
278 | EOF | |
279 | ||
280 | git -C atomic fetch --atomic origin && | |
281 | test_cmp expected atomic/actual | |
282 | ' | |
283 | ||
284 | test_expect_success 'fetch --atomic aborts all reference updates if hook aborts' ' | |
285 | test_when_finished "rm -rf \"$D\"/atomic" && | |
286 | ||
287 | cd "$D" && | |
288 | git clone . atomic && | |
289 | git branch atomic-hooks-abort-1 && | |
290 | git branch atomic-hooks-abort-2 && | |
291 | git branch atomic-hooks-abort-3 && | |
292 | git tag atomic-hooks-abort && | |
293 | head_oid=$(git rev-parse HEAD) && | |
294 | ||
295 | cat >expected <<-EOF && | |
296 | prepared | |
297 | $ZERO_OID $head_oid refs/remotes/origin/atomic-hooks-abort-1 | |
298 | $ZERO_OID $head_oid refs/remotes/origin/atomic-hooks-abort-2 | |
299 | $ZERO_OID $head_oid refs/remotes/origin/atomic-hooks-abort-3 | |
300 | $ZERO_OID $head_oid refs/tags/atomic-hooks-abort | |
301 | aborted | |
302 | $ZERO_OID $head_oid refs/remotes/origin/atomic-hooks-abort-1 | |
303 | $ZERO_OID $head_oid refs/remotes/origin/atomic-hooks-abort-2 | |
304 | $ZERO_OID $head_oid refs/remotes/origin/atomic-hooks-abort-3 | |
305 | $ZERO_OID $head_oid refs/tags/atomic-hooks-abort | |
306 | EOF | |
307 | ||
308 | rm -f atomic/actual && | |
7da7f63c | 309 | test_hook -C atomic/.git reference-transaction <<-\EOF && |
c7b190da PS |
310 | ( echo "$*" && cat ) >>actual |
311 | exit 1 | |
312 | EOF | |
313 | ||
314 | git -C atomic for-each-ref >expected-refs && | |
315 | test_must_fail git -C atomic fetch --tags --atomic origin && | |
316 | git -C atomic for-each-ref >actual-refs && | |
317 | test_cmp expected-refs actual-refs && | |
318 | test_must_be_empty atomic/.git/FETCH_HEAD | |
319 | ' | |
320 | ||
321 | test_expect_success 'fetch --atomic --append appends to FETCH_HEAD' ' | |
322 | test_when_finished "rm -rf \"$D\"/atomic" && | |
323 | ||
324 | cd "$D" && | |
325 | git clone . atomic && | |
326 | oid=$(git rev-parse HEAD) && | |
327 | ||
328 | git branch atomic-fetch-head-1 && | |
329 | git -C atomic fetch --atomic origin atomic-fetch-head-1 && | |
330 | test_line_count = 1 atomic/.git/FETCH_HEAD && | |
331 | ||
332 | git branch atomic-fetch-head-2 && | |
333 | git -C atomic fetch --atomic --append origin atomic-fetch-head-2 && | |
334 | test_line_count = 2 atomic/.git/FETCH_HEAD && | |
335 | cp atomic/.git/FETCH_HEAD expected && | |
336 | ||
7da7f63c | 337 | test_hook -C atomic reference-transaction <<-\EOF && |
c7b190da PS |
338 | exit 1 |
339 | EOF | |
340 | ||
341 | git branch atomic-fetch-head-3 && | |
342 | test_must_fail git -C atomic fetch --atomic --append origin atomic-fetch-head-3 && | |
343 | test_cmp expected atomic/.git/FETCH_HEAD | |
344 | ' | |
345 | ||
2a0cafd4 PS |
346 | test_expect_success 'fetch --atomic --prune executes a single reference transaction only' ' |
347 | test_when_finished "rm -rf \"$D\"/atomic" && | |
348 | ||
349 | cd "$D" && | |
350 | git branch scheduled-for-deletion && | |
351 | git clone . atomic && | |
352 | git branch -D scheduled-for-deletion && | |
353 | git branch new-branch && | |
354 | head_oid=$(git rev-parse HEAD) && | |
355 | ||
356 | # Fetching with the `--atomic` flag should update all references in a | |
583bc419 | 357 | # single transaction. |
2a0cafd4 PS |
358 | cat >expected <<-EOF && |
359 | prepared | |
360 | $ZERO_OID $ZERO_OID refs/remotes/origin/scheduled-for-deletion | |
2a0cafd4 PS |
361 | $ZERO_OID $head_oid refs/remotes/origin/new-branch |
362 | committed | |
583bc419 | 363 | $ZERO_OID $ZERO_OID refs/remotes/origin/scheduled-for-deletion |
2a0cafd4 PS |
364 | $ZERO_OID $head_oid refs/remotes/origin/new-branch |
365 | EOF | |
366 | ||
7da7f63c | 367 | test_hook -C atomic reference-transaction <<-\EOF && |
2a0cafd4 PS |
368 | ( echo "$*" && cat ) >>actual |
369 | EOF | |
370 | ||
371 | git -C atomic fetch --atomic --prune origin && | |
372 | test_cmp expected atomic/actual | |
373 | ' | |
374 | ||
b40a5026 DS |
375 | test_expect_success '--refmap="" ignores configured refspec' ' |
376 | cd "$TRASH_DIRECTORY" && | |
377 | git clone "$D" remote-refs && | |
83ecf26e JS |
378 | git -C remote-refs rev-parse remotes/origin/main >old && |
379 | git -C remote-refs update-ref refs/remotes/origin/main main~1 && | |
380 | git -C remote-refs rev-parse remotes/origin/main >new && | |
b40a5026 | 381 | git -C remote-refs fetch --refmap= origin "+refs/heads/*:refs/hidden/origin/*" && |
83ecf26e | 382 | git -C remote-refs rev-parse remotes/origin/main >actual && |
b40a5026 DS |
383 | test_cmp new actual && |
384 | git -C remote-refs fetch origin && | |
83ecf26e | 385 | git -C remote-refs rev-parse remotes/origin/main >actual && |
b40a5026 DS |
386 | test_cmp old actual |
387 | ' | |
388 | ||
389 | test_expect_success '--refmap="" and --prune' ' | |
83ecf26e JS |
390 | git -C remote-refs update-ref refs/remotes/origin/foo/otherbranch main && |
391 | git -C remote-refs update-ref refs/hidden/foo/otherbranch main && | |
b40a5026 DS |
392 | git -C remote-refs fetch --prune --refmap="" origin +refs/heads/*:refs/hidden/* && |
393 | git -C remote-refs rev-parse remotes/origin/foo/otherbranch && | |
394 | test_must_fail git -C remote-refs rev-parse refs/hidden/foo/otherbranch && | |
395 | git -C remote-refs fetch --prune origin && | |
396 | test_must_fail git -C remote-refs rev-parse remotes/origin/foo/otherbranch | |
397 | ' | |
398 | ||
f539d0d6 VJ |
399 | test_expect_success 'fetch tags when there is no tags' ' |
400 | ||
401 | cd "$D" && | |
402 | ||
403 | mkdir notags && | |
404 | cd notags && | |
405 | git init && | |
406 | ||
407 | git fetch -t .. | |
408 | ||
409 | ' | |
410 | ||
6c96c0f1 JH |
411 | test_expect_success 'fetch following tags' ' |
412 | ||
413 | cd "$D" && | |
c76b84a1 | 414 | git tag -a -m "annotated" anno HEAD && |
6c96c0f1 JH |
415 | git tag light HEAD && |
416 | ||
417 | mkdir four && | |
418 | cd four && | |
5c94f87e | 419 | git init && |
6c96c0f1 JH |
420 | |
421 | git fetch .. :track && | |
422 | git show-ref --verify refs/tags/anno && | |
423 | git show-ref --verify refs/tags/light | |
424 | ||
425 | ' | |
426 | ||
0997adaa MB |
427 | test_expect_success 'fetch uses remote ref names to describe new refs' ' |
428 | cd "$D" && | |
429 | git init descriptive && | |
430 | ( | |
431 | cd descriptive && | |
432 | git config remote.o.url .. && | |
433 | git config remote.o.fetch "refs/heads/*:refs/crazyheads/*" && | |
434 | git config --add remote.o.fetch "refs/others/*:refs/heads/*" && | |
435 | git fetch o | |
436 | ) && | |
437 | git tag -a -m "Descriptive tag" descriptive-tag && | |
438 | git branch descriptive-branch && | |
439 | git checkout descriptive-branch && | |
440 | echo "Nuts" >crazy && | |
441 | git add crazy && | |
442 | git commit -a -m "descriptive commit" && | |
443 | git update-ref refs/others/crazy HEAD && | |
444 | ( | |
445 | cd descriptive && | |
446 | git fetch o 2>actual && | |
927c1a64 SG |
447 | test_i18ngrep "new branch.* -> refs/crazyheads/descriptive-branch$" actual && |
448 | test_i18ngrep "new tag.* -> descriptive-tag$" actual && | |
449 | test_i18ngrep "new ref.* -> crazy$" actual | |
0997adaa | 450 | ) && |
83ecf26e | 451 | git checkout main |
0997adaa MB |
452 | ' |
453 | ||
41ac414e | 454 | test_expect_success 'fetch must not resolve short tag name' ' |
605b4978 SP |
455 | |
456 | cd "$D" && | |
457 | ||
458 | mkdir five && | |
459 | cd five && | |
460 | git init && | |
461 | ||
d492b31c | 462 | test_must_fail git fetch .. anno:five |
605b4978 SP |
463 | |
464 | ' | |
465 | ||
dd621df9 | 466 | test_expect_success 'fetch can now resolve short remote name' ' |
605b4978 SP |
467 | |
468 | cd "$D" && | |
a48fcd83 | 469 | git update-ref refs/remotes/six/HEAD HEAD && |
605b4978 SP |
470 | |
471 | mkdir six && | |
472 | cd six && | |
473 | git init && | |
474 | ||
dd621df9 | 475 | git fetch .. six:six |
605b4978 SP |
476 | ' |
477 | ||
2e0afafe JS |
478 | test_expect_success 'create bundle 1' ' |
479 | cd "$D" && | |
480 | echo >file updated again by origin && | |
481 | git commit -a -m "tip" && | |
83ecf26e | 482 | git bundle create --version=3 bundle1 main^..main |
2e0afafe JS |
483 | ' |
484 | ||
8315588b | 485 | test_expect_success 'header of bundle looks right' ' |
c5aecfc8 | 486 | cat >expect <<-EOF && |
487 | # v3 git bundle | |
488 | @object-format=$(test_oid algo) | |
489 | -OID updated by origin | |
83ecf26e | 490 | OID refs/heads/main |
c5aecfc8 | 491 | |
492 | EOF | |
493 | sed -e "s/$OID_REGEX/OID/g" -e "5q" "$D"/bundle1 >actual && | |
494 | test_cmp expect actual | |
8315588b JS |
495 | ' |
496 | ||
2e0afafe JS |
497 | test_expect_success 'create bundle 2' ' |
498 | cd "$D" && | |
83ecf26e | 499 | git bundle create bundle2 main~2..main |
2e0afafe JS |
500 | ' |
501 | ||
41ac414e | 502 | test_expect_success 'unbundle 1' ' |
2e0afafe JS |
503 | cd "$D/bundle" && |
504 | git checkout -b some-branch && | |
83ecf26e | 505 | test_must_fail git fetch "$D/bundle1" main:main |
2e0afafe JS |
506 | ' |
507 | ||
2e674a9d | 508 | |
8315588b JS |
509 | test_expect_success 'bundle 1 has only 3 files ' ' |
510 | cd "$D" && | |
9901164d | 511 | test_bundle_object_count bundle1 3 |
8315588b JS |
512 | ' |
513 | ||
2e0afafe JS |
514 | test_expect_success 'unbundle 2' ' |
515 | cd "$D/bundle" && | |
83ecf26e JS |
516 | git fetch ../bundle2 main:main && |
517 | test "tip" = "$(git log -1 --pretty=oneline main | cut -d" " -f2)" | |
2e0afafe JS |
518 | ' |
519 | ||
18449ab0 JS |
520 | test_expect_success 'bundle does not prerequisite objects' ' |
521 | cd "$D" && | |
522 | touch file2 && | |
523 | git add file2 && | |
524 | git commit -m add.file2 file2 && | |
525 | git bundle create bundle3 -1 HEAD && | |
9901164d | 526 | test_bundle_object_count bundle3 3 |
18449ab0 JS |
527 | ' |
528 | ||
7fa8254f JH |
529 | test_expect_success 'bundle should be able to create a full history' ' |
530 | ||
531 | cd "$D" && | |
83ecf26e | 532 | git tag -a -m "1.0" v1.0 main && |
7fa8254f JH |
533 | git bundle create bundle4 v1.0 |
534 | ||
535 | ' | |
536 | ||
da0204df | 537 | test_expect_success 'fetch with a non-applying branch.<name>.merge' ' |
83ecf26e JS |
538 | git config branch.main.remote yeti && |
539 | git config branch.main.merge refs/heads/bigfoot && | |
da0204df JS |
540 | git config remote.blub.url one && |
541 | git config remote.blub.fetch "refs/heads/*:refs/remotes/one/*" && | |
542 | git fetch blub | |
543 | ' | |
544 | ||
042cca38 BC |
545 | # URL supplied to fetch does not match the url of the configured branch's remote |
546 | test_expect_success 'fetch from GIT URL with a non-applying branch.<name>.merge [1]' ' | |
547 | one_head=$(cd one && git rev-parse HEAD) && | |
548 | this_head=$(git rev-parse HEAD) && | |
6106ce46 BC |
549 | git update-ref -d FETCH_HEAD && |
550 | git fetch one && | |
042cca38 BC |
551 | test $one_head = "$(git rev-parse --verify FETCH_HEAD)" && |
552 | test $this_head = "$(git rev-parse --verify HEAD)" | |
553 | ' | |
554 | ||
555 | # URL supplied to fetch matches the url of the configured branch's remote and | |
556 | # the merge spec matches the branch the remote HEAD points to | |
557 | test_expect_success 'fetch from GIT URL with a non-applying branch.<name>.merge [2]' ' | |
558 | one_ref=$(cd one && git symbolic-ref HEAD) && | |
83ecf26e JS |
559 | git config branch.main.remote blub && |
560 | git config branch.main.merge "$one_ref" && | |
042cca38 BC |
561 | git update-ref -d FETCH_HEAD && |
562 | git fetch one && | |
563 | test $one_head = "$(git rev-parse --verify FETCH_HEAD)" && | |
564 | test $this_head = "$(git rev-parse --verify HEAD)" | |
565 | ' | |
566 | ||
567 | # URL supplied to fetch matches the url of the configured branch's remote, but | |
568 | # the merge spec does not match the branch the remote HEAD points to | |
569 | test_expect_success 'fetch from GIT URL with a non-applying branch.<name>.merge [3]' ' | |
83ecf26e | 570 | git config branch.main.merge "${one_ref}_not" && |
042cca38 BC |
571 | git update-ref -d FETCH_HEAD && |
572 | git fetch one && | |
573 | test $one_head = "$(git rev-parse --verify FETCH_HEAD)" && | |
574 | test $this_head = "$(git rev-parse --verify HEAD)" | |
6106ce46 BC |
575 | ' |
576 | ||
c2015b3a JS |
577 | # the strange name is: a\!'b |
578 | test_expect_success 'quoting of a strangely named repo' ' | |
d492b31c | 579 | test_must_fail git fetch "a\\!'\''b" > result 2>&1 && |
c2015b3a JS |
580 | grep "fatal: '\''a\\\\!'\''b'\''" result |
581 | ' | |
582 | ||
c5546e88 JS |
583 | test_expect_success 'bundle should record HEAD correctly' ' |
584 | ||
585 | cd "$D" && | |
83ecf26e | 586 | git bundle create bundle5 HEAD main && |
c5546e88 | 587 | git bundle list-heads bundle5 >actual && |
83ecf26e | 588 | for h in HEAD refs/heads/main |
c5546e88 | 589 | do |
d0fd9931 | 590 | echo "$(git rev-parse --verify $h) $h" || return 1 |
c5546e88 | 591 | done >expect && |
82ebb0b6 | 592 | test_cmp expect actual |
c5546e88 JS |
593 | |
594 | ' | |
595 | ||
83ecf26e | 596 | test_expect_success 'mark initial state of origin/main' ' |
51f8c814 JK |
597 | ( |
598 | cd three && | |
83ecf26e | 599 | git tag base-origin-main refs/remotes/origin/main |
51f8c814 JK |
600 | ) |
601 | ' | |
602 | ||
f2690487 | 603 | test_expect_success 'explicit fetch should update tracking' ' |
c7015961 JH |
604 | |
605 | cd "$D" && | |
606 | git branch -f side && | |
607 | ( | |
608 | cd three && | |
83ecf26e JS |
609 | git update-ref refs/remotes/origin/main base-origin-main && |
610 | o=$(git rev-parse --verify refs/remotes/origin/main) && | |
611 | git fetch origin main && | |
612 | n=$(git rev-parse --verify refs/remotes/origin/main) && | |
f2690487 | 613 | test "$o" != "$n" && |
d492b31c | 614 | test_must_fail git rev-parse --verify refs/remotes/origin/side |
c7015961 JH |
615 | ) |
616 | ' | |
617 | ||
f2690487 | 618 | test_expect_success 'explicit pull should update tracking' ' |
c7015961 JH |
619 | |
620 | cd "$D" && | |
621 | git branch -f side && | |
622 | ( | |
623 | cd three && | |
83ecf26e JS |
624 | git update-ref refs/remotes/origin/main base-origin-main && |
625 | o=$(git rev-parse --verify refs/remotes/origin/main) && | |
626 | git pull origin main && | |
627 | n=$(git rev-parse --verify refs/remotes/origin/main) && | |
f2690487 | 628 | test "$o" != "$n" && |
d492b31c | 629 | test_must_fail git rev-parse --verify refs/remotes/origin/side |
c7015961 JH |
630 | ) |
631 | ' | |
632 | ||
c5558f80 JH |
633 | test_expect_success 'explicit --refmap is allowed only with command-line refspec' ' |
634 | cd "$D" && | |
635 | ( | |
636 | cd three && | |
637 | test_must_fail git fetch --refmap="*:refs/remotes/none/*" | |
638 | ) | |
639 | ' | |
640 | ||
641 | test_expect_success 'explicit --refmap option overrides remote.*.fetch' ' | |
642 | cd "$D" && | |
643 | git branch -f side && | |
644 | ( | |
645 | cd three && | |
83ecf26e JS |
646 | git update-ref refs/remotes/origin/main base-origin-main && |
647 | o=$(git rev-parse --verify refs/remotes/origin/main) && | |
648 | git fetch --refmap="refs/heads/*:refs/remotes/other/*" origin main && | |
649 | n=$(git rev-parse --verify refs/remotes/origin/main) && | |
c5558f80 JH |
650 | test "$o" = "$n" && |
651 | test_must_fail git rev-parse --verify refs/remotes/origin/side && | |
83ecf26e | 652 | git rev-parse --verify refs/remotes/other/main |
c5558f80 JH |
653 | ) |
654 | ' | |
655 | ||
656 | test_expect_success 'explicitly empty --refmap option disables remote.*.fetch' ' | |
657 | cd "$D" && | |
658 | git branch -f side && | |
659 | ( | |
660 | cd three && | |
83ecf26e JS |
661 | git update-ref refs/remotes/origin/main base-origin-main && |
662 | o=$(git rev-parse --verify refs/remotes/origin/main) && | |
663 | git fetch --refmap="" origin main && | |
664 | n=$(git rev-parse --verify refs/remotes/origin/main) && | |
c5558f80 JH |
665 | test "$o" = "$n" && |
666 | test_must_fail git rev-parse --verify refs/remotes/origin/side | |
667 | ) | |
668 | ' | |
669 | ||
c7015961 JH |
670 | test_expect_success 'configured fetch updates tracking' ' |
671 | ||
672 | cd "$D" && | |
673 | git branch -f side && | |
674 | ( | |
675 | cd three && | |
83ecf26e JS |
676 | git update-ref refs/remotes/origin/main base-origin-main && |
677 | o=$(git rev-parse --verify refs/remotes/origin/main) && | |
c7015961 | 678 | git fetch origin && |
83ecf26e | 679 | n=$(git rev-parse --verify refs/remotes/origin/main) && |
c7015961 JH |
680 | test "$o" != "$n" && |
681 | git rev-parse --verify refs/remotes/origin/side | |
682 | ) | |
683 | ' | |
684 | ||
823c6d56 JK |
685 | test_expect_success 'non-matching refspecs do not confuse tracking update' ' |
686 | cd "$D" && | |
687 | git update-ref refs/odd/location HEAD && | |
688 | ( | |
689 | cd three && | |
83ecf26e | 690 | git update-ref refs/remotes/origin/main base-origin-main && |
823c6d56 JK |
691 | git config --add remote.origin.fetch \ |
692 | refs/odd/location:refs/remotes/origin/odd && | |
83ecf26e JS |
693 | o=$(git rev-parse --verify refs/remotes/origin/main) && |
694 | git fetch origin main && | |
695 | n=$(git rev-parse --verify refs/remotes/origin/main) && | |
823c6d56 JK |
696 | test "$o" != "$n" && |
697 | test_must_fail git rev-parse --verify refs/remotes/origin/odd | |
698 | ) | |
699 | ' | |
700 | ||
9a7bbd1d JK |
701 | test_expect_success 'pushing nonexistent branch by mistake should not segv' ' |
702 | ||
703 | cd "$D" && | |
704 | test_must_fail git push seven no:no | |
705 | ||
706 | ' | |
707 | ||
49420252 JH |
708 | test_expect_success 'auto tag following fetches minimum' ' |
709 | ||
710 | cd "$D" && | |
711 | git clone .git follow && | |
712 | git checkout HEAD^0 && | |
713 | ( | |
714 | for i in 1 2 3 4 5 6 7 | |
715 | do | |
716 | echo $i >>file && | |
717 | git commit -m $i -a && | |
718 | git tag -a -m $i excess-$i || exit 1 | |
719 | done | |
720 | ) && | |
83ecf26e | 721 | git checkout main && |
49420252 JH |
722 | ( |
723 | cd follow && | |
724 | git fetch | |
725 | ) | |
726 | ' | |
727 | ||
8ee5d731 JS |
728 | test_expect_success 'refuse to fetch into the current branch' ' |
729 | ||
83ecf26e | 730 | test_must_fail git fetch . side:main |
8ee5d731 JS |
731 | |
732 | ' | |
733 | ||
734 | test_expect_success 'fetch into the current branch with --update-head-ok' ' | |
735 | ||
83ecf26e | 736 | git fetch --update-head-ok . side:main |
8ee5d731 JS |
737 | |
738 | ' | |
739 | ||
db3c293e JT |
740 | test_expect_success 'fetch --dry-run does not touch FETCH_HEAD, but still prints what would be written' ' |
741 | rm -f .git/FETCH_HEAD err && | |
742 | git fetch --dry-run . 2>err && | |
743 | ! test -f .git/FETCH_HEAD && | |
744 | grep FETCH_HEAD err | |
745 | ' | |
746 | ||
747 | test_expect_success '--no-write-fetch-head does not touch FETCH_HEAD, and does not print what would be written' ' | |
748 | rm -f .git/FETCH_HEAD err && | |
749 | git fetch --no-write-fetch-head . 2>err && | |
750 | ! test -f .git/FETCH_HEAD && | |
751 | ! grep FETCH_HEAD err | |
887952b8 JH |
752 | ' |
753 | ||
754 | test_expect_success '--write-fetch-head gets defeated by --dry-run' ' | |
755 | rm -f .git/FETCH_HEAD && | |
756 | git fetch --dry-run --write-fetch-head . && | |
757 | ! test -f .git/FETCH_HEAD | |
758 | ' | |
759 | ||
95c96d48 | 760 | test_expect_success "should be able to fetch with duplicate refspecs" ' |
aa982856 TR |
761 | mkdir dups && |
762 | ( | |
763 | cd dups && | |
764 | git init && | |
83ecf26e | 765 | git config branch.main.remote three && |
aa982856 TR |
766 | git config remote.three.url ../three/.git && |
767 | git config remote.three.fetch +refs/heads/*:refs/remotes/origin/* && | |
768 | git config --add remote.three.fetch +refs/heads/*:refs/remotes/origin/* && | |
769 | git fetch three | |
770 | ) | |
95c96d48 JP |
771 | ' |
772 | ||
60650a48 JH |
773 | test_expect_success 'LHS of refspec follows ref disambiguation rules' ' |
774 | mkdir lhs-ambiguous && | |
775 | ( | |
776 | cd lhs-ambiguous && | |
777 | git init server && | |
778 | test_commit -C server unwanted && | |
779 | test_commit -C server wanted && | |
780 | ||
781 | git init client && | |
782 | ||
783 | # Check a name coming after "refs" alphabetically ... | |
784 | git -C server update-ref refs/heads/s wanted && | |
785 | git -C server update-ref refs/heads/refs/heads/s unwanted && | |
786 | git -C client fetch ../server +refs/heads/s:refs/heads/checkthis && | |
787 | git -C server rev-parse wanted >expect && | |
788 | git -C client rev-parse checkthis >actual && | |
789 | test_cmp expect actual && | |
790 | ||
791 | # ... and one before. | |
792 | git -C server update-ref refs/heads/q wanted && | |
793 | git -C server update-ref refs/heads/refs/heads/q unwanted && | |
794 | git -C client fetch ../server +refs/heads/q:refs/heads/checkthis && | |
795 | git -C server rev-parse wanted >expect && | |
796 | git -C client rev-parse checkthis >actual && | |
797 | test_cmp expect actual && | |
798 | ||
799 | # Tags are preferred over branches like refs/{heads,tags}/* | |
800 | git -C server update-ref refs/tags/t wanted && | |
801 | git -C server update-ref refs/heads/t unwanted && | |
802 | git -C client fetch ../server +t:refs/heads/checkthis && | |
803 | git -C server rev-parse wanted >expect && | |
804 | git -C client rev-parse checkthis >actual | |
805 | ) | |
806 | ' | |
807 | ||
50f26bd0 DS |
808 | test_expect_success 'fetch.writeCommitGraph' ' |
809 | git clone three write && | |
810 | ( | |
811 | cd three && | |
812 | test_commit new | |
813 | ) && | |
814 | ( | |
815 | cd write && | |
816 | git -c fetch.writeCommitGraph fetch origin && | |
817 | test_path_is_file .git/objects/info/commit-graphs/commit-graph-chain | |
818 | ) | |
819 | ' | |
820 | ||
cb99a34e | 821 | test_expect_success 'fetch.writeCommitGraph with submodules' ' |
e88aab91 DS |
822 | git clone dups super && |
823 | ( | |
824 | cd super && | |
825 | git submodule add "file://$TRASH_DIRECTORY/three" && | |
826 | git commit -m "add submodule" | |
827 | ) && | |
828 | git clone "super" super-clone && | |
829 | ( | |
830 | cd super-clone && | |
831 | rm -rf .git/objects/info && | |
832 | git -c fetch.writeCommitGraph=true fetch origin && | |
833 | test_path_is_file .git/objects/info/commit-graphs/commit-graph-chain | |
834 | ) | |
835 | ' | |
836 | ||
737c5a9c MS |
837 | # configured prune tests |
838 | ||
839 | set_config_tristate () { | |
840 | # var=$1 val=$2 | |
841 | case "$2" in | |
59caf52d ÆAB |
842 | unset) |
843 | test_unconfig "$1" | |
844 | ;; | |
845 | *) | |
846 | git config "$1" "$2" | |
e1790f92 ÆAB |
847 | key=$(echo $1 | sed -e 's/^remote\.origin/fetch/') |
848 | git_fetch_c="$git_fetch_c -c $key=$2" | |
59caf52d | 849 | ;; |
737c5a9c MS |
850 | esac |
851 | } | |
852 | ||
853 | test_configured_prune () { | |
e1790f92 ÆAB |
854 | test_configured_prune_type "$@" "name" |
855 | test_configured_prune_type "$@" "link" | |
856 | } | |
737c5a9c | 857 | |
e1790f92 | 858 | test_configured_prune_type () { |
eca142d3 ÆAB |
859 | fetch_prune=$1 |
860 | remote_origin_prune=$2 | |
e249ce0c ÆAB |
861 | fetch_prune_tags=$3 |
862 | remote_origin_prune_tags=$4 | |
863 | expected_branch=$5 | |
864 | expected_tag=$6 | |
865 | cmdline=$7 | |
866 | mode=$8 | |
e1790f92 ÆAB |
867 | |
868 | if test -z "$cmdline_setup" | |
869 | then | |
870 | test_expect_success 'setup cmdline_setup variable for subsequent test' ' | |
871 | remote_url="file://$(git -C one config remote.origin.url)" && | |
872 | remote_fetch="$(git -C one config remote.origin.fetch)" && | |
873 | cmdline_setup="\"$remote_url\" \"$remote_fetch\"" | |
874 | ' | |
875 | fi | |
876 | ||
877 | if test "$mode" = 'link' | |
878 | then | |
879 | new_cmdline="" | |
880 | ||
881 | if test "$cmdline" = "" | |
882 | then | |
883 | new_cmdline=$cmdline_setup | |
884 | else | |
885 | new_cmdline=$(printf "%s" "$cmdline" | perl -pe 's[origin(?!/)]["'"$remote_url"'"]g') | |
886 | fi | |
887 | ||
97716d21 ÆAB |
888 | if test "$fetch_prune_tags" = 'true' || |
889 | test "$remote_origin_prune_tags" = 'true' | |
890 | then | |
891 | if ! printf '%s' "$cmdline\n" | grep -q refs/remotes/origin/ | |
892 | then | |
893 | new_cmdline="$new_cmdline refs/tags/*:refs/tags/*" | |
894 | fi | |
895 | fi | |
896 | ||
e1790f92 ÆAB |
897 | cmdline="$new_cmdline" |
898 | fi | |
899 | ||
e249ce0c | 900 | test_expect_success "$mode prune fetch.prune=$1 remote.origin.prune=$2 fetch.pruneTags=$3 remote.origin.pruneTags=$4${7:+ $7}; branch:$5 tag:$6" ' |
737c5a9c MS |
901 | # make sure a newbranch is there in . and also in one |
902 | git branch -f newbranch && | |
ca3065e7 | 903 | git tag -f newtag && |
737c5a9c MS |
904 | ( |
905 | cd one && | |
906 | test_unconfig fetch.prune && | |
e249ce0c | 907 | test_unconfig fetch.pruneTags && |
737c5a9c | 908 | test_unconfig remote.origin.prune && |
e249ce0c | 909 | test_unconfig remote.origin.pruneTags && |
e1790f92 | 910 | git fetch '"$cmdline_setup"' && |
ca3065e7 ÆAB |
911 | git rev-parse --verify refs/remotes/origin/newbranch && |
912 | git rev-parse --verify refs/tags/newtag | |
99094a7a | 913 | ) && |
737c5a9c | 914 | |
d3651121 | 915 | # now remove them |
737c5a9c | 916 | git branch -d newbranch && |
ca3065e7 | 917 | git tag -d newtag && |
737c5a9c MS |
918 | |
919 | # then test | |
920 | ( | |
921 | cd one && | |
e1790f92 | 922 | git_fetch_c="" && |
737c5a9c | 923 | set_config_tristate fetch.prune $fetch_prune && |
e249ce0c | 924 | set_config_tristate fetch.pruneTags $fetch_prune_tags && |
737c5a9c | 925 | set_config_tristate remote.origin.prune $remote_origin_prune && |
e249ce0c | 926 | set_config_tristate remote.origin.pruneTags $remote_origin_prune_tags && |
737c5a9c | 927 | |
e1790f92 ÆAB |
928 | if test "$mode" != "link" |
929 | then | |
930 | git_fetch_c="" | |
931 | fi && | |
932 | git$git_fetch_c fetch '"$cmdline"' && | |
eca142d3 | 933 | case "$expected_branch" in |
737c5a9c MS |
934 | pruned) |
935 | test_must_fail git rev-parse --verify refs/remotes/origin/newbranch | |
936 | ;; | |
937 | kept) | |
938 | git rev-parse --verify refs/remotes/origin/newbranch | |
939 | ;; | |
ca3065e7 ÆAB |
940 | esac && |
941 | case "$expected_tag" in | |
942 | pruned) | |
943 | test_must_fail git rev-parse --verify refs/tags/newtag | |
944 | ;; | |
945 | kept) | |
946 | git rev-parse --verify refs/tags/newtag | |
947 | ;; | |
737c5a9c MS |
948 | esac |
949 | ) | |
950 | ' | |
951 | } | |
952 | ||
bf16ab79 ÆAB |
953 | # $1 config: fetch.prune |
954 | # $2 config: remote.<name>.prune | |
e249ce0c ÆAB |
955 | # $3 config: fetch.pruneTags |
956 | # $4 config: remote.<name>.pruneTags | |
957 | # $5 expect: branch to be pruned? | |
958 | # $6 expect: tag to be pruned? | |
959 | # $7 git-fetch $cmdline: | |
bf16ab79 | 960 | # |
e249ce0c ÆAB |
961 | # $1 $2 $3 $4 $5 $6 $7 |
962 | test_configured_prune unset unset unset unset kept kept "" | |
963 | test_configured_prune unset unset unset unset kept kept "--no-prune" | |
964 | test_configured_prune unset unset unset unset pruned kept "--prune" | |
965 | test_configured_prune unset unset unset unset kept pruned \ | |
6fb23f56 | 966 | "--prune origin refs/tags/*:refs/tags/*" |
e249ce0c | 967 | test_configured_prune unset unset unset unset pruned pruned \ |
6fb23f56 | 968 | "--prune origin refs/tags/*:refs/tags/* +refs/heads/*:refs/remotes/origin/*" |
ca3065e7 | 969 | |
e249ce0c ÆAB |
970 | test_configured_prune false unset unset unset kept kept "" |
971 | test_configured_prune false unset unset unset kept kept "--no-prune" | |
972 | test_configured_prune false unset unset unset pruned kept "--prune" | |
ca3065e7 | 973 | |
e249ce0c ÆAB |
974 | test_configured_prune true unset unset unset pruned kept "" |
975 | test_configured_prune true unset unset unset pruned kept "--prune" | |
976 | test_configured_prune true unset unset unset kept kept "--no-prune" | |
ca3065e7 | 977 | |
e249ce0c ÆAB |
978 | test_configured_prune unset false unset unset kept kept "" |
979 | test_configured_prune unset false unset unset kept kept "--no-prune" | |
980 | test_configured_prune unset false unset unset pruned kept "--prune" | |
ca3065e7 | 981 | |
e249ce0c ÆAB |
982 | test_configured_prune false false unset unset kept kept "" |
983 | test_configured_prune false false unset unset kept kept "--no-prune" | |
984 | test_configured_prune false false unset unset pruned kept "--prune" | |
985 | test_configured_prune false false unset unset kept pruned \ | |
6fb23f56 | 986 | "--prune origin refs/tags/*:refs/tags/*" |
e249ce0c | 987 | test_configured_prune false false unset unset pruned pruned \ |
6fb23f56 | 988 | "--prune origin refs/tags/*:refs/tags/* +refs/heads/*:refs/remotes/origin/*" |
ca3065e7 | 989 | |
e249ce0c ÆAB |
990 | test_configured_prune true false unset unset kept kept "" |
991 | test_configured_prune true false unset unset pruned kept "--prune" | |
992 | test_configured_prune true false unset unset kept kept "--no-prune" | |
ca3065e7 | 993 | |
e249ce0c ÆAB |
994 | test_configured_prune unset true unset unset pruned kept "" |
995 | test_configured_prune unset true unset unset kept kept "--no-prune" | |
996 | test_configured_prune unset true unset unset pruned kept "--prune" | |
ca3065e7 | 997 | |
e249ce0c ÆAB |
998 | test_configured_prune false true unset unset pruned kept "" |
999 | test_configured_prune false true unset unset kept kept "--no-prune" | |
1000 | test_configured_prune false true unset unset pruned kept "--prune" | |
ca3065e7 | 1001 | |
e249ce0c ÆAB |
1002 | test_configured_prune true true unset unset pruned kept "" |
1003 | test_configured_prune true true unset unset pruned kept "--prune" | |
1004 | test_configured_prune true true unset unset kept kept "--no-prune" | |
1005 | test_configured_prune true true unset unset kept pruned \ | |
6fb23f56 | 1006 | "--prune origin refs/tags/*:refs/tags/*" |
e249ce0c | 1007 | test_configured_prune true true unset unset pruned pruned \ |
6fb23f56 | 1008 | "--prune origin refs/tags/*:refs/tags/* +refs/heads/*:refs/remotes/origin/*" |
737c5a9c | 1009 | |
97716d21 | 1010 | # --prune-tags on its own does nothing, needs --prune as well, same |
6d12b533 | 1011 | # for fetch.pruneTags without fetch.prune |
97716d21 ÆAB |
1012 | test_configured_prune unset unset unset unset kept kept "--prune-tags" |
1013 | test_configured_prune unset unset true unset kept kept "" | |
1014 | test_configured_prune unset unset unset true kept kept "" | |
1015 | ||
1016 | # These will prune the tags | |
1017 | test_configured_prune unset unset unset unset pruned pruned "--prune --prune-tags" | |
1018 | test_configured_prune true unset true unset pruned pruned "" | |
1019 | test_configured_prune unset true unset true pruned pruned "" | |
1020 | ||
1021 | # remote.<name>.pruneTags overrides fetch.pruneTags, just like | |
1022 | # remote.<name>.prune overrides fetch.prune if set. | |
1023 | test_configured_prune true unset true unset pruned pruned "" | |
1024 | test_configured_prune false true false true pruned pruned "" | |
1025 | test_configured_prune true false true false kept kept "" | |
1026 | ||
1027 | # When --prune-tags is supplied it's ignored if an explicit refspec is | |
1028 | # given, same for the configuration options. | |
1029 | test_configured_prune unset unset unset unset pruned kept \ | |
1030 | "--prune --prune-tags origin +refs/heads/*:refs/remotes/origin/*" | |
1031 | test_configured_prune unset unset true unset pruned kept \ | |
1032 | "--prune origin +refs/heads/*:refs/remotes/origin/*" | |
1033 | test_configured_prune unset unset unset true pruned kept \ | |
1034 | "--prune origin +refs/heads/*:refs/remotes/origin/*" | |
1035 | ||
1036 | # Pruning that also takes place if a file:// url replaces a named | |
6317972c | 1037 | # remote. However, because there's no implicit |
97716d21 ÆAB |
1038 | # +refs/heads/*:refs/remotes/origin/* refspec and supplying it on the |
1039 | # command-line negates --prune-tags, the branches will not be pruned. | |
1040 | test_configured_prune_type unset unset unset unset kept kept "origin --prune-tags" "name" | |
1041 | test_configured_prune_type unset unset unset unset kept kept "origin --prune-tags" "link" | |
1042 | test_configured_prune_type unset unset unset unset pruned pruned "origin --prune --prune-tags" "name" | |
6317972c | 1043 | test_configured_prune_type unset unset unset unset kept pruned "origin --prune --prune-tags" "link" |
97716d21 | 1044 | test_configured_prune_type unset unset unset unset pruned pruned "--prune --prune-tags origin" "name" |
6317972c | 1045 | test_configured_prune_type unset unset unset unset kept pruned "--prune --prune-tags origin" "link" |
97716d21 ÆAB |
1046 | test_configured_prune_type unset unset true unset pruned pruned "--prune origin" "name" |
1047 | test_configured_prune_type unset unset true unset kept pruned "--prune origin" "link" | |
1048 | test_configured_prune_type unset unset unset true pruned pruned "--prune origin" "name" | |
1049 | test_configured_prune_type unset unset unset true kept pruned "--prune origin" "link" | |
1050 | test_configured_prune_type true unset true unset pruned pruned "origin" "name" | |
1051 | test_configured_prune_type true unset true unset kept pruned "origin" "link" | |
1052 | test_configured_prune_type unset true true unset pruned pruned "origin" "name" | |
1053 | test_configured_prune_type unset true true unset kept pruned "origin" "link" | |
1054 | test_configured_prune_type unset true unset true pruned pruned "origin" "name" | |
1055 | test_configured_prune_type unset true unset true kept pruned "origin" "link" | |
1056 | ||
6317972c ÆAB |
1057 | # When all remote.origin.fetch settings are deleted a --prune |
1058 | # --prune-tags still implicitly supplies refs/tags/*:refs/tags/* so | |
1059 | # tags, but not tracking branches, will be deleted. | |
97716d21 ÆAB |
1060 | test_expect_success 'remove remote.origin.fetch "one"' ' |
1061 | ( | |
1062 | cd one && | |
1063 | git config --unset-all remote.origin.fetch | |
1064 | ) | |
1065 | ' | |
1066 | test_configured_prune_type unset unset unset unset kept pruned "origin --prune --prune-tags" "name" | |
6317972c | 1067 | test_configured_prune_type unset unset unset unset kept pruned "origin --prune --prune-tags" "link" |
737c5a9c | 1068 | |
efe4be12 TR |
1069 | test_expect_success 'all boundary commits are excluded' ' |
1070 | test_commit base && | |
1071 | test_commit oneside && | |
1072 | git checkout HEAD^ && | |
1073 | test_commit otherside && | |
83ecf26e | 1074 | git checkout main && |
efe4be12 TR |
1075 | test_tick && |
1076 | git merge otherside && | |
1077 | ad=$(git log --no-walk --format=%ad HEAD) && | |
83ecf26e | 1078 | git bundle create twoside-boundary.bdl main --since="$ad" && |
9901164d | 1079 | test_bundle_object_count --thin twoside-boundary.bdl 3 |
95c96d48 JP |
1080 | ' |
1081 | ||
4b3b33a7 TM |
1082 | test_expect_success 'fetch --prune prints the remotes url' ' |
1083 | git branch goodbye && | |
1084 | git clone . only-prunes && | |
1085 | git branch -D goodbye && | |
1086 | ( | |
1087 | cd only-prunes && | |
1088 | git fetch --prune origin 2>&1 | head -n1 >../actual | |
1089 | ) && | |
1090 | echo "From ${D}/." >expect && | |
1108cea7 | 1091 | test_cmp expect actual |
4b3b33a7 TM |
1092 | ' |
1093 | ||
10a6cc88 TM |
1094 | test_expect_success 'branchname D/F conflict resolved by --prune' ' |
1095 | git branch dir/file && | |
1096 | git clone . prune-df-conflict && | |
1097 | git branch -D dir/file && | |
1098 | git branch dir && | |
1099 | ( | |
1100 | cd prune-df-conflict && | |
1101 | git fetch --prune && | |
1102 | git rev-parse origin/dir >../actual | |
1103 | ) && | |
1104 | git rev-parse dir >expect && | |
1105 | test_cmp expect actual | |
1106 | ' | |
1107 | ||
4c224081 JK |
1108 | test_expect_success 'fetching a one-level ref works' ' |
1109 | test_commit extra && | |
1110 | git reset --hard HEAD^ && | |
1111 | git update-ref refs/foo extra && | |
1112 | git init one-level && | |
1113 | ( | |
1114 | cd one-level && | |
1115 | git fetch .. HEAD refs/foo | |
1116 | ) | |
1117 | ' | |
1118 | ||
0898c962 JS |
1119 | test_expect_success 'fetching with auto-gc does not lock up' ' |
1120 | write_script askyesno <<-\EOF && | |
1121 | echo "$*" && | |
1122 | false | |
1123 | EOF | |
1124 | git clone "file://$D" auto-gc && | |
1125 | test_commit test2 && | |
816c1930 MG |
1126 | ( |
1127 | cd auto-gc && | |
12e73a3c | 1128 | git config fetch.unpackLimit 1 && |
816c1930 | 1129 | git config gc.autoPackLimit 1 && |
bb05510e | 1130 | git config gc.autoDetach false && |
a95ce124 | 1131 | GIT_ASK_YESNO="$D/askyesno" git fetch --verbose >fetch.out 2>&1 && |
12e73a3c | 1132 | test_i18ngrep "Auto packing the repository" fetch.out && |
816c1930 MG |
1133 | ! grep "Should I try again" fetch.out |
1134 | ) | |
0898c962 JS |
1135 | ' |
1136 | ||
a926c4b9 | 1137 | test_expect_success 'fetch aligned output' ' |
6bc91f23 NTND |
1138 | git clone . full-output && |
1139 | test_commit looooooooooooong-tag && | |
1140 | ( | |
1141 | cd full-output && | |
a4d4e32a PK |
1142 | git -c fetch.output=full fetch origin >actual 2>&1 && |
1143 | grep -e "->" actual | cut -c 22- >../actual | |
6bc91f23 NTND |
1144 | ) && |
1145 | cat >expect <<-\EOF && | |
66713e84 | 1146 | main -> origin/main |
6bc91f23 NTND |
1147 | looooooooooooong-tag -> looooooooooooong-tag |
1148 | EOF | |
1149 | test_cmp expect actual | |
1150 | ' | |
1151 | ||
a926c4b9 | 1152 | test_expect_success 'fetch compact output' ' |
bc437d10 NTND |
1153 | git clone . compact && |
1154 | test_commit extraaa && | |
1155 | ( | |
1156 | cd compact && | |
a4d4e32a PK |
1157 | git -c fetch.output=compact fetch origin >actual 2>&1 && |
1158 | grep -e "->" actual | cut -c 22- >../actual | |
bc437d10 NTND |
1159 | ) && |
1160 | cat >expect <<-\EOF && | |
66713e84 | 1161 | main -> origin/* |
bc437d10 NTND |
1162 | extraaa -> * |
1163 | EOF | |
1164 | test_cmp expect actual | |
1165 | ' | |
1166 | ||
12b18266 SG |
1167 | test_expect_success '--no-show-forced-updates' ' |
1168 | mkdir forced-updates && | |
1169 | ( | |
1170 | cd forced-updates && | |
1171 | git init && | |
1172 | test_commit 1 && | |
1173 | test_commit 2 | |
1174 | ) && | |
1175 | git clone forced-updates forced-update-clone && | |
1176 | git clone forced-updates no-forced-update-clone && | |
1177 | git -C forced-updates reset --hard HEAD~1 && | |
1178 | ( | |
1179 | cd forced-update-clone && | |
1180 | git fetch --show-forced-updates origin 2>output && | |
1181 | test_i18ngrep "(forced update)" output | |
1182 | ) && | |
1183 | ( | |
1184 | cd no-forced-update-clone && | |
1185 | git fetch --no-show-forced-updates origin 2>output && | |
1186 | test_i18ngrep ! "(forced update)" output | |
1187 | ) | |
1188 | ' | |
1189 | ||
3390e42a JT |
1190 | setup_negotiation_tip () { |
1191 | SERVER="$1" | |
1192 | URL="$2" | |
1193 | USE_PROTOCOL_V2="$3" | |
1194 | ||
1195 | rm -rf "$SERVER" client trace && | |
83ecf26e | 1196 | git init -b main "$SERVER" && |
3390e42a JT |
1197 | test_commit -C "$SERVER" alpha_1 && |
1198 | test_commit -C "$SERVER" alpha_2 && | |
1199 | git -C "$SERVER" checkout --orphan beta && | |
1200 | test_commit -C "$SERVER" beta_1 && | |
1201 | test_commit -C "$SERVER" beta_2 && | |
1202 | ||
1203 | git clone "$URL" client && | |
1204 | ||
1205 | if test "$USE_PROTOCOL_V2" -eq 1 | |
1206 | then | |
1207 | git -C "$SERVER" config protocol.version 2 && | |
1208 | git -C client config protocol.version 2 | |
1209 | fi && | |
1210 | ||
1211 | test_commit -C "$SERVER" beta_s && | |
83ecf26e | 1212 | git -C "$SERVER" checkout main && |
3390e42a JT |
1213 | test_commit -C "$SERVER" alpha_s && |
1214 | git -C "$SERVER" tag -d alpha_1 alpha_2 beta_1 beta_2 | |
1215 | } | |
1216 | ||
1217 | check_negotiation_tip () { | |
1218 | # Ensure that {alpha,beta}_1 are sent as "have", but not {alpha_beta}_2 | |
1219 | ALPHA_1=$(git -C client rev-parse alpha_1) && | |
1220 | grep "fetch> have $ALPHA_1" trace && | |
1221 | BETA_1=$(git -C client rev-parse beta_1) && | |
1222 | grep "fetch> have $BETA_1" trace && | |
1223 | ALPHA_2=$(git -C client rev-parse alpha_2) && | |
1224 | ! grep "fetch> have $ALPHA_2" trace && | |
1225 | BETA_2=$(git -C client rev-parse beta_2) && | |
1226 | ! grep "fetch> have $BETA_2" trace | |
1227 | } | |
1228 | ||
1229 | test_expect_success '--negotiation-tip limits "have" lines sent' ' | |
1230 | setup_negotiation_tip server server 0 && | |
1231 | GIT_TRACE_PACKET="$(pwd)/trace" git -C client fetch \ | |
1232 | --negotiation-tip=alpha_1 --negotiation-tip=beta_1 \ | |
1233 | origin alpha_s beta_s && | |
1234 | check_negotiation_tip | |
1235 | ' | |
1236 | ||
1237 | test_expect_success '--negotiation-tip understands globs' ' | |
1238 | setup_negotiation_tip server server 0 && | |
1239 | GIT_TRACE_PACKET="$(pwd)/trace" git -C client fetch \ | |
1240 | --negotiation-tip=*_1 \ | |
1241 | origin alpha_s beta_s && | |
1242 | check_negotiation_tip | |
1243 | ' | |
1244 | ||
1245 | test_expect_success '--negotiation-tip understands abbreviated SHA-1' ' | |
1246 | setup_negotiation_tip server server 0 && | |
1247 | GIT_TRACE_PACKET="$(pwd)/trace" git -C client fetch \ | |
1248 | --negotiation-tip=$(git -C client rev-parse --short alpha_1) \ | |
1249 | --negotiation-tip=$(git -C client rev-parse --short beta_1) \ | |
1250 | origin alpha_s beta_s && | |
1251 | check_negotiation_tip | |
1252 | ' | |
1253 | ||
82823118 JT |
1254 | test_expect_success '--negotiation-tip rejects missing OIDs' ' |
1255 | setup_negotiation_tip server server 0 && | |
1256 | test_must_fail git -C client fetch \ | |
1257 | --negotiation-tip=alpha_1 \ | |
1258 | --negotiation-tip=$(test_oid zero) \ | |
1259 | origin alpha_s beta_s 2>err && | |
1260 | cat >fatal-expect <<-EOF && | |
1261 | fatal: the object $(test_oid zero) does not exist | |
1262 | EOF | |
1263 | grep fatal: err >fatal-actual && | |
1264 | test_cmp fatal-expect fatal-actual | |
1265 | ' | |
1266 | ||
3390e42a JT |
1267 | . "$TEST_DIRECTORY"/lib-httpd.sh |
1268 | start_httpd | |
1269 | ||
1270 | test_expect_success '--negotiation-tip limits "have" lines sent with HTTP protocol v2' ' | |
1271 | setup_negotiation_tip "$HTTPD_DOCUMENT_ROOT_PATH/server" \ | |
1272 | "$HTTPD_URL/smart/server" 1 && | |
1273 | GIT_TRACE_PACKET="$(pwd)/trace" git -C client fetch \ | |
1274 | --negotiation-tip=alpha_1 --negotiation-tip=beta_1 \ | |
1275 | origin alpha_s beta_s && | |
1276 | check_negotiation_tip | |
1277 | ' | |
1278 | ||
12b18266 SG |
1279 | # DO NOT add non-httpd-specific tests here, because the last part of this |
1280 | # test script is only executed when httpd is available and enabled. | |
cdbd70c4 | 1281 | |
7be1d62c | 1282 | test_done |