Skip to content

Commit 368d278

Browse files
Shubhamlmpgitster
authored andcommitted
t7001: avoid using cd outside of subshells
Avoid using `cd` outside of subshells since, if the test fails, there is no guarantee that the current working directory is the expected one, which may cause subsequent tests to run in the wrong directory. While at it, make some other tests more concise by replacing simple subshells with `git -C`. Signed-off-by: Shubham Verma <[email protected]> Reviewed-by: Eric Sunshine <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent dd72154 commit 368d278

File tree

1 file changed

+11
-32
lines changed

1 file changed

+11
-32
lines changed

t/t7001-mv.sh

Lines changed: 11 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -11,12 +11,12 @@ test_expect_success 'prepare reference tree' '
1111
'
1212

1313
test_expect_success 'moving the file out of subdirectory' '
14-
cd path0 && git mv COPYING ../path1/COPYING
14+
git -C path0 mv COPYING ../path1/COPYING
1515
'
1616

1717
# in path0 currently
1818
test_expect_success 'commiting the change' '
19-
cd .. && git commit -m move-out -a
19+
git commit -m move-out -a
2020
'
2121

2222
test_expect_success 'checking the commit' '
@@ -25,12 +25,12 @@ test_expect_success 'checking the commit' '
2525
'
2626

2727
test_expect_success 'moving the file back into subdirectory' '
28-
cd path0 && git mv ../path1/COPYING COPYING
28+
git -C path0 mv ../path1/COPYING COPYING
2929
'
3030

3131
# in path0 currently
3232
test_expect_success 'commiting the change' '
33-
cd .. && git commit -m move-in -a
33+
git commit -m move-in -a
3434
'
3535

3636
test_expect_success 'checking the commit' '
@@ -328,10 +328,7 @@ test_expect_success 'git mv moves a submodule with a .git directory and no .gitm
328328
git mv sub mod/sub &&
329329
! test -e sub &&
330330
[ "$entry" = "$(git ls-files --stage mod/sub | cut -f 1)" ] &&
331-
(
332-
cd mod/sub &&
333-
git status
334-
) &&
331+
git -C mod/sub status &&
335332
git update-index --refresh &&
336333
git diff-files --quiet
337334
'
@@ -351,10 +348,7 @@ test_expect_success 'git mv moves a submodule with a .git directory and .gitmodu
351348
git mv sub mod/sub &&
352349
! test -e sub &&
353350
[ "$entry" = "$(git ls-files --stage mod/sub | cut -f 1)" ] &&
354-
(
355-
cd mod/sub &&
356-
git status
357-
) &&
351+
git -C mod/sub status &&
358352
echo mod/sub >expected &&
359353
git config -f .gitmodules submodule.sub.path >actual &&
360354
test_cmp expected actual &&
@@ -368,16 +362,10 @@ test_expect_success 'git mv moves a submodule with gitfile' '
368362
git submodule update &&
369363
entry="$(git ls-files --stage sub | cut -f 1)" &&
370364
mkdir mod &&
371-
(
372-
cd mod &&
373-
git mv ../sub/ .
374-
) &&
365+
git -C mod mv ../sub/ . &&
375366
! test -e sub &&
376367
[ "$entry" = "$(git ls-files --stage mod/sub | cut -f 1)" ] &&
377-
(
378-
cd mod/sub &&
379-
git status
380-
) &&
368+
git -C mod/sub status &&
381369
echo mod/sub >expected &&
382370
git config -f .gitmodules submodule.sub.path >actual &&
383371
test_cmp expected actual &&
@@ -396,10 +384,7 @@ test_expect_success 'mv does not complain when no .gitmodules file is found' '
396384
test_must_be_empty actual.err &&
397385
! test -e sub &&
398386
[ "$entry" = "$(git ls-files --stage mod/sub | cut -f 1)" ] &&
399-
(
400-
cd mod/sub &&
401-
git status
402-
) &&
387+
git -C mod/sub status &&
403388
git update-index --refresh &&
404389
git diff-files --quiet
405390
'
@@ -420,10 +405,7 @@ test_expect_success 'mv will error out on a modified .gitmodules file unless sta
420405
test_must_be_empty actual.err &&
421406
! test -e sub &&
422407
[ "$entry" = "$(git ls-files --stage mod/sub | cut -f 1)" ] &&
423-
(
424-
cd mod/sub &&
425-
git status
426-
) &&
408+
git -C mod/sub status &&
427409
git update-index --refresh &&
428410
git diff-files --quiet
429411
'
@@ -441,10 +423,7 @@ test_expect_success 'mv issues a warning when section is not found in .gitmodule
441423
test_i18ncmp expect.err actual.err &&
442424
! test -e sub &&
443425
[ "$entry" = "$(git ls-files --stage mod/sub | cut -f 1)" ] &&
444-
(
445-
cd mod/sub &&
446-
git status
447-
) &&
426+
git -C mod/sub status &&
448427
git update-index --refresh &&
449428
git diff-files --quiet
450429
'

0 commit comments

Comments
 (0)