summaryrefslogtreecommitdiff
path: root/t/t7001-mv.sh
diff options
context:
space:
mode:
authorShubham Verma <shubhunic@gmail.com>2021-02-12 01:17:00 +0530
committerJunio C Hamano <gitster@pobox.com>2021-02-11 13:42:16 -0800
commit368d2782499af9fbe9db73aed2ffbba53772374a (patch)
tree79f9da7c7921c044566e1ddfbf5ffabdfbae61a6 /t/t7001-mv.sh
parentdd72154149a48120f135de28b0202ac5de34d17b (diff)
downloadgit-368d2782499af9fbe9db73aed2ffbba53772374a.tar.gz
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 <shubhunic@gmail.com> Reviewed-by: Eric Sunshine <sunshine@sunshineco.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Diffstat (limited to 't/t7001-mv.sh')
-rwxr-xr-xt/t7001-mv.sh43
1 files changed, 11 insertions, 32 deletions
diff --git a/t/t7001-mv.sh b/t/t7001-mv.sh
index 02fbc90dea..efbcba12d3 100755
--- a/t/t7001-mv.sh
+++ b/t/t7001-mv.sh
@@ -11,12 +11,12 @@ test_expect_success 'prepare reference tree' '
'
test_expect_success 'moving the file out of subdirectory' '
- cd path0 && git mv COPYING ../path1/COPYING
+ git -C path0 mv COPYING ../path1/COPYING
'
# in path0 currently
test_expect_success 'commiting the change' '
- cd .. && git commit -m move-out -a
+ git commit -m move-out -a
'
test_expect_success 'checking the commit' '
@@ -25,12 +25,12 @@ test_expect_success 'checking the commit' '
'
test_expect_success 'moving the file back into subdirectory' '
- cd path0 && git mv ../path1/COPYING COPYING
+ git -C path0 mv ../path1/COPYING COPYING
'
# in path0 currently
test_expect_success 'commiting the change' '
- cd .. && git commit -m move-in -a
+ git commit -m move-in -a
'
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
git mv sub mod/sub &&
! test -e sub &&
[ "$entry" = "$(git ls-files --stage mod/sub | cut -f 1)" ] &&
- (
- cd mod/sub &&
- git status
- ) &&
+ git -C mod/sub status &&
git update-index --refresh &&
git diff-files --quiet
'
@@ -351,10 +348,7 @@ test_expect_success 'git mv moves a submodule with a .git directory and .gitmodu
git mv sub mod/sub &&
! test -e sub &&
[ "$entry" = "$(git ls-files --stage mod/sub | cut -f 1)" ] &&
- (
- cd mod/sub &&
- git status
- ) &&
+ git -C mod/sub status &&
echo mod/sub >expected &&
git config -f .gitmodules submodule.sub.path >actual &&
test_cmp expected actual &&
@@ -368,16 +362,10 @@ test_expect_success 'git mv moves a submodule with gitfile' '
git submodule update &&
entry="$(git ls-files --stage sub | cut -f 1)" &&
mkdir mod &&
- (
- cd mod &&
- git mv ../sub/ .
- ) &&
+ git -C mod mv ../sub/ . &&
! test -e sub &&
[ "$entry" = "$(git ls-files --stage mod/sub | cut -f 1)" ] &&
- (
- cd mod/sub &&
- git status
- ) &&
+ git -C mod/sub status &&
echo mod/sub >expected &&
git config -f .gitmodules submodule.sub.path >actual &&
test_cmp expected actual &&
@@ -396,10 +384,7 @@ test_expect_success 'mv does not complain when no .gitmodules file is found' '
test_must_be_empty actual.err &&
! test -e sub &&
[ "$entry" = "$(git ls-files --stage mod/sub | cut -f 1)" ] &&
- (
- cd mod/sub &&
- git status
- ) &&
+ git -C mod/sub status &&
git update-index --refresh &&
git diff-files --quiet
'
@@ -420,10 +405,7 @@ test_expect_success 'mv will error out on a modified .gitmodules file unless sta
test_must_be_empty actual.err &&
! test -e sub &&
[ "$entry" = "$(git ls-files --stage mod/sub | cut -f 1)" ] &&
- (
- cd mod/sub &&
- git status
- ) &&
+ git -C mod/sub status &&
git update-index --refresh &&
git diff-files --quiet
'
@@ -441,10 +423,7 @@ test_expect_success 'mv issues a warning when section is not found in .gitmodule
test_i18ncmp expect.err actual.err &&
! test -e sub &&
[ "$entry" = "$(git ls-files --stage mod/sub | cut -f 1)" ] &&
- (
- cd mod/sub &&
- git status
- ) &&
+ git -C mod/sub status &&
git update-index --refresh &&
git diff-files --quiet
'