t5510: stop changing top-level working directory

Several tests in t5510 do a bare "cd subrepo", not in a subshell. This changes the working directory for subsequent tests. As a result, almost every test has to start with "cd $D" to go back to the top-level. Our usual style is to do per-test environment changes like this in a subshell, so that tests can assume they are starting at the top-level $TRASH_DIRECTORY. Let's switch to that style, which lets us drop all of that extra path-handling. Most cases can switch to using a subshell, but in a few spots we can simplify by doing "git init foo && git -C foo ...". We do have to make sure that we weren't intentionally touching the environment in any code which was moved into a subshell (e.g., with a test_when_finished), but that isn't the case for any of these tests. All of the references to the $D variable can go away, replaced generally with $PWD or $TRASH_DIRECTORY (if we use it inside a chdir'd subshell). Note in one test, "fetch --prune prints the remotes url", we make sure to use $(pwd) to get the Windows-style path on that platform (for the other tests, the exact form doesn't matter). Signed-off-by: Jeff King <peff@peff.net> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Jeff King committed Aug 19, 2025 at 15:26 UTC 1de2903c0f065b4c14326a741a57cc7e7b63610f
1 file changed +161 -195
t/t5510-fetch.sh
+161 -195
@@ -14,8 +14,6 @@ then
14 test_done
15 fi
16
17 -D=$(pwd)
18 -
17 test_expect_success setup '
18 echo >file original &&
19 git add file &&
@@ -51,46 +49,50 @@ test_expect_success "clone and setup child repos" '
49 '
50
51 test_expect_success "fetch test" '
54 - cd "$D" &&
52 echo >file updated by origin &&
53 git commit -a -m "updated by origin" &&
57 - cd two &&
58 - git fetch &&
59 - git rev-parse --verify refs/heads/one &&
60 - mine=$(git rev-parse refs/heads/one) &&
61 - his=$(cd ../one && git rev-parse refs/heads/main) &&
62 - test "z$mine" = "z$his"
54 + (
55 + cd two &&
56 + git fetch &&
57 + git rev-parse --verify refs/heads/one &&
58 + mine=$(git rev-parse refs/heads/one) &&
59 + his=$(cd ../one && git rev-parse refs/heads/main) &&
60 + test "z$mine" = "z$his"
61 + )
62 '
63
64 test_expect_success "fetch test for-merge" '
66 - cd "$D" &&
67 - cd three &&
68 - git fetch &&
69 - git rev-parse --verify refs/heads/two &&
70 - git rev-parse --verify refs/heads/one &&
71 - main_in_two=$(cd ../two && git rev-parse main) &&
72 - one_in_two=$(cd ../two && git rev-parse one) &&
73 - {
74 - echo "$one_in_two " &&
75 - echo "$main_in_two not-for-merge"
76 - } >expected &&
77 - cut -f -2 .git/FETCH_HEAD >actual &&
78 - test_cmp expected actual'
65 + (
66 + cd three &&
67 + git fetch &&
68 + git rev-parse --verify refs/heads/two &&
69 + git rev-parse --verify refs/heads/one &&
70 + main_in_two=$(cd ../two && git rev-parse main) &&
71 + one_in_two=$(cd ../two && git rev-parse one) &&
72 + {
73 + echo "$one_in_two " &&
74 + echo "$main_in_two not-for-merge"
75 + } >expected &&
76 + cut -f -2 .git/FETCH_HEAD >actual &&
77 + test_cmp expected actual
78 + )
79 +'
80
81 test_expect_success "fetch test remote HEAD" '
81 - cd "$D" &&
82 - cd two &&
83 - git fetch &&
84 - git rev-parse --verify refs/remotes/origin/HEAD &&
85 - git rev-parse --verify refs/remotes/origin/main &&
86 - head=$(git rev-parse refs/remotes/origin/HEAD) &&
87 - branch=$(git rev-parse refs/remotes/origin/main) &&
88 - test "z$head" = "z$branch"'
82 + (
83 + cd two &&
84 + git fetch &&
85 + git rev-parse --verify refs/remotes/origin/HEAD &&
86 + git rev-parse --verify refs/remotes/origin/main &&
87 + head=$(git rev-parse refs/remotes/origin/HEAD) &&
88 + branch=$(git rev-parse refs/remotes/origin/main) &&
89 + test "z$head" = "z$branch"
90 + )
91 +'
92
93 test_expect_success "fetch test remote HEAD in bare repository" '
94 test_when_finished rm -rf barerepo &&
95 (
93 - cd "$D" &&
96 git init --bare barerepo &&
97 cd barerepo &&
98 git remote add upstream ../two &&
@@ -105,23 +107,24 @@ test_expect_success "fetch test remote HEAD in bare repository" '
107
108
109 test_expect_success "fetch test remote HEAD change" '
108 - cd "$D" &&
109 - cd two &&
110 - git switch -c other &&
111 - git push -u origin other &&
112 - git rev-parse --verify refs/remotes/origin/HEAD &&
113 - git rev-parse --verify refs/remotes/origin/main &&
114 - git rev-parse --verify refs/remotes/origin/other &&
115 - git remote set-head origin other &&
116 - git fetch &&
117 - head=$(git rev-parse refs/remotes/origin/HEAD) &&
118 - branch=$(git rev-parse refs/remotes/origin/other) &&
119 - test "z$head" = "z$branch"'
110 + (
111 + cd two &&
112 + git switch -c other &&
113 + git push -u origin other &&
114 + git rev-parse --verify refs/remotes/origin/HEAD &&
115 + git rev-parse --verify refs/remotes/origin/main &&
116 + git rev-parse --verify refs/remotes/origin/other &&
117 + git remote set-head origin other &&
118 + git fetch &&
119 + head=$(git rev-parse refs/remotes/origin/HEAD) &&
120 + branch=$(git rev-parse refs/remotes/origin/other) &&
121 + test "z$head" = "z$branch"
122 + )
123 +'
124
125 test_expect_success "fetch test followRemoteHEAD never" '
122 - test_when_finished "git -C \"$D/two\" config unset remote.origin.followRemoteHEAD" &&
126 + test_when_finished "git -C two config unset remote.origin.followRemoteHEAD" &&
127 (
124 - cd "$D" &&
128 cd two &&
129 git update-ref --no-deref -d refs/remotes/origin/HEAD &&
130 git config set remote.origin.followRemoteHEAD "never" &&
@@ -134,9 +137,8 @@ test_expect_success "fetch test followRemoteHEAD never" '
137 '
138
139 test_expect_success "fetch test followRemoteHEAD warn no change" '
137 - test_when_finished "git -C \"$D/two\" config unset remote.origin.followRemoteHEAD" &&
140 + test_when_finished "git -C two config unset remote.origin.followRemoteHEAD" &&
141 (
139 - cd "$D" &&
142 cd two &&
143 git rev-parse --verify refs/remotes/origin/other &&
144 git remote set-head origin other &&
@@ -154,9 +156,8 @@ test_expect_success "fetch test followRemoteHEAD warn no change" '
156 '
157
158 test_expect_success "fetch test followRemoteHEAD warn create" '
157 - test_when_finished "git -C \"$D/two\" config unset remote.origin.followRemoteHEAD" &&
159 + test_when_finished "git -C two config unset remote.origin.followRemoteHEAD" &&
160 (
159 - cd "$D" &&
161 cd two &&
162 git update-ref --no-deref -d refs/remotes/origin/HEAD &&
163 git config set remote.origin.followRemoteHEAD "warn" &&
@@ -170,9 +171,8 @@ test_expect_success "fetch test followRemoteHEAD warn create" '
171 '
172
173 test_expect_success "fetch test followRemoteHEAD warn detached" '
173 - test_when_finished "git -C \"$D/two\" config unset remote.origin.followRemoteHEAD" &&
174 + test_when_finished "git -C two config unset remote.origin.followRemoteHEAD" &&
175 (
175 - cd "$D" &&
176 cd two &&
177 git update-ref --no-deref -d refs/remotes/origin/HEAD &&
178 git update-ref refs/remotes/origin/HEAD HEAD &&
@@ -187,9 +187,8 @@ test_expect_success "fetch test followRemoteHEAD warn detached" '
187 '
188
189 test_expect_success "fetch test followRemoteHEAD warn quiet" '
190 - test_when_finished "git -C \"$D/two\" config unset remote.origin.followRemoteHEAD" &&
190 + test_when_finished "git -C two config unset remote.origin.followRemoteHEAD" &&
191 (
192 - cd "$D" &&
192 cd two &&
193 git rev-parse --verify refs/remotes/origin/other &&
194 git remote set-head origin other &&
@@ -205,9 +204,8 @@ test_expect_success "fetch test followRemoteHEAD warn quiet" '
204 '
205
206 test_expect_success "fetch test followRemoteHEAD warn-if-not-branch branch is same" '
208 - test_when_finished "git -C \"$D/two\" config unset remote.origin.followRemoteHEAD" &&
207 + test_when_finished "git -C two config unset remote.origin.followRemoteHEAD" &&
208 (
210 - cd "$D" &&
209 cd two &&
210 git rev-parse --verify refs/remotes/origin/other &&
211 git remote set-head origin other &&
@@ -223,9 +221,8 @@ test_expect_success "fetch test followRemoteHEAD warn-if-not-branch branch is sa
221 '
222
223 test_expect_success "fetch test followRemoteHEAD warn-if-not-branch branch is different" '
226 - test_when_finished "git -C \"$D/two\" config unset remote.origin.followRemoteHEAD" &&
224 + test_when_finished "git -C two config unset remote.origin.followRemoteHEAD" &&
225 (
228 - cd "$D" &&
226 cd two &&
227 git rev-parse --verify refs/remotes/origin/other &&
228 git remote set-head origin other &&
@@ -243,9 +240,8 @@ test_expect_success "fetch test followRemoteHEAD warn-if-not-branch branch is di
240 '
241
242 test_expect_success "fetch test followRemoteHEAD always" '
246 - test_when_finished "git -C \"$D/two\" config unset remote.origin.followRemoteHEAD" &&
243 + test_when_finished "git -C two config unset remote.origin.followRemoteHEAD" &&
244 (
248 - cd "$D" &&
245 cd two &&
246 git rev-parse --verify refs/remotes/origin/other &&
247 git remote set-head origin other &&
@@ -260,9 +256,8 @@ test_expect_success "fetch test followRemoteHEAD always" '
256 '
257
258 test_expect_success 'followRemoteHEAD does not kick in with refspecs' '
263 - test_when_finished "git -C \"$D/two\" config unset remote.origin.followRemoteHEAD" &&
259 + test_when_finished "git -C two config unset remote.origin.followRemoteHEAD" &&
260 (
265 - cd "$D" &&
261 cd two &&
262 git remote set-head origin other &&
263 git config set remote.origin.followRemoteHEAD always &&
@@ -274,93 +269,100 @@ test_expect_success 'followRemoteHEAD does not kick in with refspecs' '
269 '
270
271 test_expect_success 'fetch --prune on its own works as expected' '
277 - cd "$D" &&
272 git clone . prune &&
279 - cd prune &&
280 - git update-ref refs/remotes/origin/extrabranch main &&
273 + (
274 + cd prune &&
275 + git update-ref refs/remotes/origin/extrabranch main &&
276
282 - git fetch --prune origin &&
283 - test_must_fail git rev-parse origin/extrabranch
277 + git fetch --prune origin &&
278 + test_must_fail git rev-parse origin/extrabranch
279 + )
280 '
281
282 test_expect_success 'fetch --prune with a branch name keeps branches' '
287 - cd "$D" &&
283 git clone . prune-branch &&
289 - cd prune-branch &&
290 - git update-ref refs/remotes/origin/extrabranch main &&
284 + (
285 + cd prune-branch &&
286 + git update-ref refs/remotes/origin/extrabranch main &&
287
292 - git fetch --prune origin main &&
293 - git rev-parse origin/extrabranch
288 + git fetch --prune origin main &&
289 + git rev-parse origin/extrabranch
290 + )
291 '
292
293 test_expect_success 'fetch --prune with a namespace keeps other namespaces' '
297 - cd "$D" &&
294 git clone . prune-namespace &&
299 - cd prune-namespace &&
295 + (
296 + cd prune-namespace &&
297
301 - git fetch --prune origin refs/heads/a/*:refs/remotes/origin/a/* &&
302 - git rev-parse origin/main
298 + git fetch --prune origin refs/heads/a/*:refs/remotes/origin/a/* &&
299 + git rev-parse origin/main
300 + )
301 '
302
303 test_expect_success 'fetch --prune handles overlapping refspecs' '
306 - cd "$D" &&
304 git update-ref refs/pull/42/head main &&
305 git clone . prune-overlapping &&
309 - cd prune-overlapping &&
310 - git config --add remote.origin.fetch refs/pull/*/head:refs/remotes/origin/pr/* &&
306 + (
307 + cd prune-overlapping &&
308 + git config --add remote.origin.fetch refs/pull/*/head:refs/remotes/origin/pr/* &&
309
312 - git fetch --prune origin &&
313 - git rev-parse origin/main &&
314 - git rev-parse origin/pr/42 &&
310 + git fetch --prune origin &&
311 + git rev-parse origin/main &&
312 + git rev-parse origin/pr/42 &&
313
316 - git config --unset-all remote.origin.fetch &&
317 - git config remote.origin.fetch refs/pull/*/head:refs/remotes/origin/pr/* &&
318 - git config --add remote.origin.fetch refs/heads/*:refs/remotes/origin/* &&
314 + git config --unset-all remote.origin.fetch &&
315 + git config remote.origin.fetch refs/pull/*/head:refs/remotes/origin/pr/* &&
316 + git config --add remote.origin.fetch refs/heads/*:refs/remotes/origin/* &&
317
320 - git fetch --prune origin &&
321 - git rev-parse origin/main &&
322 - git rev-parse origin/pr/42
318 + git fetch --prune origin &&
319 + git rev-parse origin/main &&
320 + git rev-parse origin/pr/42
321 + )
322 '
323
324 test_expect_success 'fetch --prune --tags prunes branches but not tags' '
326 - cd "$D" &&
325 git clone . prune-tags &&
328 - cd prune-tags &&
329 - git tag sometag main &&
330 - # Create what looks like a remote-tracking branch from an earlier
331 - # fetch that has since been deleted from the remote:
332 - git update-ref refs/remotes/origin/fake-remote main &&
333 -
334 - git fetch --prune --tags origin &&
335 - git rev-parse origin/main &&
336 - test_must_fail git rev-parse origin/fake-remote &&
337 - git rev-parse sometag
326 + (
327 + cd prune-tags &&
328 + git tag sometag main &&
329 + # Create what looks like a remote-tracking branch from an earlier
330 + # fetch that has since been deleted from the remote:
331 + git update-ref refs/remotes/origin/fake-remote main &&
332 +
333 + git fetch --prune --tags origin &&
334 + git rev-parse origin/main &&
335 + test_must_fail git rev-parse origin/fake-remote &&
336 + git rev-parse sometag
337 + )
338 '
339
340 test_expect_success 'fetch --prune --tags with branch does not prune other things' '
341 - cd "$D" &&
341 git clone . prune-tags-branch &&
343 - cd prune-tags-branch &&
344 - git tag sometag main &&
345 - git update-ref refs/remotes/origin/extrabranch main &&
342 + (
343 + cd prune-tags-branch &&
344 + git tag sometag main &&
345 + git update-ref refs/remotes/origin/extrabranch main &&
346
347 - git fetch --prune --tags origin main &&
348 - git rev-parse origin/extrabranch &&
349 - git rev-parse sometag
347 + git fetch --prune --tags origin main &&
348 + git rev-parse origin/extrabranch &&
349 + git rev-parse sometag
350 + )
351 '
352
353 test_expect_success 'fetch --prune --tags with refspec prunes based on refspec' '
353 - cd "$D" &&
354 git clone . prune-tags-refspec &&
355 - cd prune-tags-refspec &&
356 - git tag sometag main &&
357 - git update-ref refs/remotes/origin/foo/otherbranch main &&
358 - git update-ref refs/remotes/origin/extrabranch main &&
359 -
360 - git fetch --prune --tags origin refs/heads/foo/*:refs/remotes/origin/foo/* &&
361 - test_must_fail git rev-parse refs/remotes/origin/foo/otherbranch &&
362 - git rev-parse origin/extrabranch &&
363 - git rev-parse sometag
355 + (
356 + cd prune-tags-refspec &&
357 + git tag sometag main &&
358 + git update-ref refs/remotes/origin/foo/otherbranch main &&
359 + git update-ref refs/remotes/origin/extrabranch main &&
360 +
361 + git fetch --prune --tags origin refs/heads/foo/*:refs/remotes/origin/foo/* &&
362 + test_must_fail git rev-parse refs/remotes/origin/foo/otherbranch &&
363 + git rev-parse origin/extrabranch &&
364 + git rev-parse sometag
365 + )
366 '
367
368 test_expect_success 'fetch --tags gets tags even without a configured remote' '
@@ -381,21 +383,21 @@ test_expect_success 'fetch --tags gets tags even without a configured remote' '
383 '
384
385 test_expect_success REFFILES 'fetch --prune fails to delete branches' '
384 - cd "$D" &&
386 git clone . prune-fail &&
386 - cd prune-fail &&
387 - git update-ref refs/remotes/origin/extrabranch main &&
388 - git pack-refs --all &&
389 - : this will prevent --prune from locking packed-refs for deleting refs, but adding loose refs still succeeds &&
390 - >.git/packed-refs.new &&
387 + (
388 + cd prune-fail &&
389 + git update-ref refs/remotes/origin/extrabranch main &&
390 + git pack-refs --all &&
391 + : this will prevent --prune from locking packed-refs for deleting refs, but adding loose refs still succeeds &&
392 + >.git/packed-refs.new &&
393
392 - test_must_fail git fetch --prune origin
394 + test_must_fail git fetch --prune origin
395 + )
396 '
397
398 test_expect_success 'fetch --atomic works with a single branch' '
396 - test_when_finished "rm -rf \"$D\"/atomic" &&
399 + test_when_finished "rm -rf atomic" &&
400
398 - cd "$D" &&
401 git clone . atomic &&
402 git branch atomic-branch &&
403 oid=$(git rev-parse atomic-branch) &&
@@ -408,9 +410,8 @@ test_expect_success 'fetch --atomic works with a single branch' '
410 '
411
412 test_expect_success 'fetch --atomic works with multiple branches' '
411 - test_when_finished "rm -rf \"$D\"/atomic" &&
413 + test_when_finished "rm -rf atomic" &&
414
413 - cd "$D" &&
415 git clone . atomic &&
416 git branch atomic-branch-1 &&
417 git branch atomic-branch-2 &&
@@ -423,9 +424,8 @@ test_expect_success 'fetch --atomic works with multiple branches' '
424 '
425
426 test_expect_success 'fetch --atomic works with mixed branches and tags' '
426 - test_when_finished "rm -rf \"$D\"/atomic" &&
427 + test_when_finished "rm -rf atomic" &&
428
428 - cd "$D" &&
429 git clone . atomic &&
430 git branch atomic-mixed-branch &&
431 git tag atomic-mixed-tag &&
@@ -437,9 +437,8 @@ test_expect_success 'fetch --atomic works with mixed branches and tags' '
437 '
438
439 test_expect_success 'fetch --atomic prunes references' '
440 - test_when_finished "rm -rf \"$D\"/atomic" &&
440 + test_when_finished "rm -rf atomic" &&
441
442 - cd "$D" &&
442 git branch atomic-prune-delete &&
443 git clone . atomic &&
444 git branch --delete atomic-prune-delete &&
@@ -453,9 +452,8 @@ test_expect_success 'fetch --atomic prunes references' '
452 '
453
454 test_expect_success 'fetch --atomic aborts with non-fast-forward update' '
456 - test_when_finished "rm -rf \"$D\"/atomic" &&
455 + test_when_finished "rm -rf atomic" &&
456
458 - cd "$D" &&
457 git branch atomic-non-ff &&
458 git clone . atomic &&
459 git rev-parse HEAD >actual &&
@@ -472,9 +470,8 @@ test_expect_success 'fetch --atomic aborts with non-fast-forward update' '
470 '
471
472 test_expect_success 'fetch --atomic executes a single reference transaction only' '
475 - test_when_finished "rm -rf \"$D\"/atomic" &&
473 + test_when_finished "rm -rf atomic" &&
474
477 - cd "$D" &&
475 git clone . atomic &&
476 git branch atomic-hooks-1 &&
477 git branch atomic-hooks-2 &&
@@ -499,9 +496,8 @@ test_expect_success 'fetch --atomic executes a single reference transaction only
496 '
497
498 test_expect_success 'fetch --atomic aborts all reference updates if hook aborts' '
502 - test_when_finished "rm -rf \"$D\"/atomic" &&
499 + test_when_finished "rm -rf atomic" &&
500
504 - cd "$D" &&
501 git clone . atomic &&
502 git branch atomic-hooks-abort-1 &&
503 git branch atomic-hooks-abort-2 &&
@@ -536,9 +532,8 @@ test_expect_success 'fetch --atomic aborts all reference updates if hook aborts'
532 '
533
534 test_expect_success 'fetch --atomic --append appends to FETCH_HEAD' '
539 - test_when_finished "rm -rf \"$D\"/atomic" &&
535 + test_when_finished "rm -rf atomic" &&
536
541 - cd "$D" &&
537 git clone . atomic &&
538 oid=$(git rev-parse HEAD) &&
539
@@ -574,8 +569,7 @@ test_expect_success REFFILES 'fetch --atomic fails transaction if reference lock
569 '
570
571 test_expect_success '--refmap="" ignores configured refspec' '
577 - cd "$TRASH_DIRECTORY" &&
578 - git clone "$D" remote-refs &&
572 + git clone . remote-refs &&
573 git -C remote-refs rev-parse remotes/origin/main >old &&
574 git -C remote-refs update-ref refs/remotes/origin/main main~1 &&
575 git -C remote-refs rev-parse remotes/origin/main >new &&
@@ -599,34 +593,26 @@ test_expect_success '--refmap="" and --prune' '
593
594 test_expect_success 'fetch tags when there is no tags' '
595
602 - cd "$D" &&
603 -
604 - mkdir notags &&
605 - cd notags &&
606 - git init &&
607 -
608 - git fetch -t ..
596 + git init notags &&
597 + git -C notags fetch -t ..
598
599 '
600
601 test_expect_success 'fetch following tags' '
602
614 - cd "$D" &&
603 git tag -a -m "annotated" anno HEAD &&
604 git tag light HEAD &&
605
618 - mkdir four &&
619 - cd four &&
620 - git init &&
621 -
622 - git fetch .. :track &&
623 - git show-ref --verify refs/tags/anno &&
624 - git show-ref --verify refs/tags/light
625 -
606 + git init four &&
607 + (
608 + cd four &&
609 + git fetch .. :track &&
610 + git show-ref --verify refs/tags/anno &&
611 + git show-ref --verify refs/tags/light
612 + )
613 '
614
615 test_expect_success 'fetch uses remote ref names to describe new refs' '
629 - cd "$D" &&
616 git init descriptive &&
617 (
618 cd descriptive &&
@@ -654,30 +640,20 @@ test_expect_success 'fetch uses remote ref names to describe new refs' '
640
641 test_expect_success 'fetch must not resolve short tag name' '
642
657 - cd "$D" &&
658 -
659 - mkdir five &&
660 - cd five &&
661 - git init &&
662 -
663 - test_must_fail git fetch .. anno:five
643 + git init five &&
644 + test_must_fail git -C five fetch .. anno:five
645
646 '
647
648 test_expect_success 'fetch can now resolve short remote name' '
649
669 - cd "$D" &&
650 git update-ref refs/remotes/six/HEAD HEAD &&
651
672 - mkdir six &&
673 - cd six &&
674 - git init &&
675 -
676 - git fetch .. six:six
652 + git init six &&
653 + git -C six fetch .. six:six
654 '
655
656 test_expect_success 'create bundle 1' '
680 - cd "$D" &&
657 echo >file updated again by origin &&
658 git commit -a -m "tip" &&
659 git bundle create --version=3 bundle1 main^..main
@@ -691,35 +667,36 @@ test_expect_success 'header of bundle looks right' '
667 OID refs/heads/main
668
669 EOF
694 - sed -e "s/$OID_REGEX/OID/g" -e "5q" "$D"/bundle1 >actual &&
670 + sed -e "s/$OID_REGEX/OID/g" -e "5q" bundle1 >actual &&
671 test_cmp expect actual
672 '
673
674 test_expect_success 'create bundle 2' '
699 - cd "$D" &&
675 git bundle create bundle2 main~2..main
676 '
677
678 test_expect_success 'unbundle 1' '
704 - cd "$D/bundle" &&
705 - git checkout -b some-branch &&
706 - test_must_fail git fetch "$D/bundle1" main:main
679 + (
680 + cd bundle &&
681 + git checkout -b some-branch &&
682 + test_must_fail git fetch bundle1 main:main
683 + )
684 '
685
686
687 test_expect_success 'bundle 1 has only 3 files ' '
711 - cd "$D" &&
688 test_bundle_object_count bundle1 3
689 '
690
691 test_expect_success 'unbundle 2' '
716 - cd "$D/bundle" &&
717 - git fetch ../bundle2 main:main &&
718 - test "tip" = "$(git log -1 --pretty=oneline main | cut -d" " -f2)"
692 + (
693 + cd bundle &&
694 + git fetch ../bundle2 main:main &&
695 + test "tip" = "$(git log -1 --pretty=oneline main | cut -d" " -f2)"
696 + )
697 '
698
699 test_expect_success 'bundle does not prerequisite objects' '
722 - cd "$D" &&
700 touch file2 &&
701 git add file2 &&
702 git commit -m add.file2 file2 &&
@@ -729,7 +706,6 @@ test_expect_success 'bundle does not prerequisite objects' '
706
707 test_expect_success 'bundle should be able to create a full history' '
708
732 - cd "$D" &&
709 git tag -a -m "1.0" v1.0 main &&
710 git bundle create bundle4 v1.0
711
@@ -783,7 +759,6 @@ test_expect_success 'quoting of a strangely named repo' '
759
760 test_expect_success 'bundle should record HEAD correctly' '
761
786 - cd "$D" &&
762 git bundle create bundle5 HEAD main &&
763 git bundle list-heads bundle5 >actual &&
764 for h in HEAD refs/heads/main
@@ -803,7 +778,6 @@ test_expect_success 'mark initial state of origin/main' '
778
779 test_expect_success 'explicit fetch should update tracking' '
780
806 - cd "$D" &&
781 git branch -f side &&
782 (
783 cd three &&
@@ -818,7 +792,6 @@ test_expect_success 'explicit fetch should update tracking' '
792
793 test_expect_success 'explicit pull should update tracking' '
794
821 - cd "$D" &&
795 git branch -f side &&
796 (
797 cd three &&
@@ -832,7 +805,6 @@ test_expect_success 'explicit pull should update tracking' '
805 '
806
807 test_expect_success 'explicit --refmap is allowed only with command-line refspec' '
835 - cd "$D" &&
808 (
809 cd three &&
810 test_must_fail git fetch --refmap="*:refs/remotes/none/*"
@@ -840,7 +812,6 @@ test_expect_success 'explicit --refmap is allowed only with command-line refspec
812 '
813
814 test_expect_success 'explicit --refmap option overrides remote.*.fetch' '
843 - cd "$D" &&
815 git branch -f side &&
816 (
817 cd three &&
@@ -855,7 +826,6 @@ test_expect_success 'explicit --refmap option overrides remote.*.fetch' '
826 '
827
828 test_expect_success 'explicitly empty --refmap option disables remote.*.fetch' '
858 - cd "$D" &&
829 git branch -f side &&
830 (
831 cd three &&
@@ -870,7 +840,6 @@ test_expect_success 'explicitly empty --refmap option disables remote.*.fetch' '
840
841 test_expect_success 'configured fetch updates tracking' '
842
873 - cd "$D" &&
843 git branch -f side &&
844 (
845 cd three &&
@@ -884,7 +853,6 @@ test_expect_success 'configured fetch updates tracking' '
853 '
854
855 test_expect_success 'non-matching refspecs do not confuse tracking update' '
887 - cd "$D" &&
856 git update-ref refs/odd/location HEAD &&
857 (
858 cd three &&
@@ -901,14 +869,12 @@ test_expect_success 'non-matching refspecs do not confuse tracking update' '
869
870 test_expect_success 'pushing nonexistent branch by mistake should not segv' '
871
904 - cd "$D" &&
872 test_must_fail git push seven no:no
873
874 '
875
876 test_expect_success 'auto tag following fetches minimum' '
877
911 - cd "$D" &&
878 git clone .git follow &&
879 git checkout HEAD^0 &&
880 (
@@ -1307,7 +1273,7 @@ test_expect_success 'fetch --prune prints the remotes url' '
1273 cd only-prunes &&
1274 git fetch --prune origin 2>&1 | head -n1 >../actual
1275 ) &&
1310 - echo "From ${D}/." >expect &&
1276 + echo "From $(pwd)/." >expect &&
1277 test_cmp expect actual
1278 '
1279
@@ -1357,14 +1323,14 @@ test_expect_success 'fetching with auto-gc does not lock up' '
1323 echo "$*" &&
1324 false
1325 EOF
1360 - git clone "file://$D" auto-gc &&
1326 + git clone "file://$PWD" auto-gc &&
1327 test_commit test2 &&
1328 (
1329 cd auto-gc &&
1330 git config fetch.unpackLimit 1 &&
1331 git config gc.autoPackLimit 1 &&
1332 git config gc.autoDetach false &&
1367 - GIT_ASK_YESNO="$D/askyesno" git fetch --verbose >fetch.out 2>&1 &&
1333 + GIT_ASK_YESNO="$TRASH_DIRECTORY/askyesno" git fetch --verbose >fetch.out 2>&1 &&
1334 test_grep "Auto packing the repository" fetch.out &&
1335 ! grep "Should I try again" fetch.out
1336 )