test-lib: use subshell instead of cd $new && .. && cd $old
PATCH 1/1 test-lib: use subshell instead of cd $new && .. && cd $old
Change the test_create_repo code added in v1.2.2~6 to use a subshell instead of keeping track of the old working directory and cd-ing back when it's done.
--- t/test-lib.sh | 6 ++---- 1 files changed, 2 insertions(+), 4 deletions(-)
t/test-lib.sh +2 -4
@@ -687,14 +687,12 @@ test_when_finished () { test_create_repo () { test "$#" = 1 || error "bug in the test script: not 1 parameter to test-create-repo" - owd=`pwd` repo="$1" mkdir -p "$repo" - cd "$repo" || error "Cannot setup test environment" + (cd "$repo" || error "Cannot setup test environment" "$GIT_EXEC_PATH/git-init" "--template=$GIT_BUILD_DIR/templates/blt/" >&3 2>&4 || error "cannot run git init -- have you built things yet?" - mv .git/hooks .git/hooks-disabled - cd "$owd" + mv .git/hooks .git/hooks-disabled) } test_done () {
Signature · 1 line
1.7.2.2.518.gf0ba8
Quoted 5 lines · Ævar Arnfjörð Bjarmason
+++
b/t/test-lib.sht/test-lib.sh +0
-0@@ -687,14 +687,12 @@ test_when_finished () { test_create_repo () { test "$#" = 1 || error "bug in the test script: not 1 parameter to test-create-repo"
t/test-lib.sh test_when_finished () { · line 695
Quoted 10 lines
t/test-lib.sh +2
-4- owd=`pwd` repo="$1" mkdir -p "$repo" - cd "$repo" || error "Cannot setup test environment" + (cd "$repo" || error "Cannot setup test environment" "$GIT_EXEC_PATH/git-init" "--template=$GIT_BUILD_DIR/templates/blt/" >&3 2>&4 || error "cannot run git init -- have you built things yet?" - mv .git/hooks .git/hooks-disabled - cd "$owd" + mv .git/hooks .git/hooks-disabled)
Style: why not use
( cd "$repo" ... ... .git/hooks-disabled )
?
Quoted 20 lines · Jonathan Nieder
Quoted 7 lines · Ævar Arnfjörð Bjarmason
+++
b/t/test-lib.sht/test-lib.sh +0
-0@@ -687,14 +687,12 @@ test_when_finished () { test_create_repo () {test "$#" = 1 ||
error "bug in the test script: not 1 parameter to test-create-repo"
- owd=pwd
repo="$1"Quoted 8 lines
mkdir -p "$repo"
- cd "$repo" || error "Cannot setup test environment"
+ (cd "$repo" || error "Cannot setup test environment" "$GIT_EXEC_PATH/git-init" "--template=$GIT_BUILD_DIR/templates/blt/" >&3 2>&4 || error "cannot run git init -- have you built things yet?"
- mv .git/hooks .git/hooks-disabled
- cd "$owd"
+ mv .git/hooks .git/hooks-disabled)Style: why not use
Quoted 5 lines
(
cd "$repo" ...
... .git/hooks-disabled
)
I've seen both used and I don't know which is preferred.
Quoted 13 lines · Ævar Arnfjörð Bjarmason
Quoted 12 lines · Jonathan Nieder
Quoted 7 lines · Ævar Arnfjörð Bjarmason
- cd "$repo" || error "Cannot setup test environment"
+ (cd "$repo" || error "Cannot setup test environment" "$GIT_EXEC_PATH/git-init" "--template=$GIT_BUILD_DIR/templates/blt/" >&3 2>&4 || error "cannot run git init -- have you built things yet?"
- mv .git/hooks .git/hooks-disabled
- cd "$owd"
+ mv .git/hooks .git/hooks-disabled)Style: why not use
Quoted 7 lines
Quoted 5 lines
(
cd "$repo" ...
... .git/hooks-disabled
)I've seen both used and I don't know which is preferred.
Okay. I maintain that the latter is way more readable. Is there any advantage to the former?
Whichever the project chooses can be enshrined inDocumentation/CodingGuidelines, of course.
Quoted 20 lines · Jonathan Nieder
Quoted 5 lines · Ævar Arnfjörð Bjarmason
+++
b/t/test-lib.sht/test-lib.sh +0
-0@@ -687,14 +687,12 @@ test_when_finished () { test_create_repo () { test "$#" = 1 || error "bug in the test script: not 1 parameter to test-create-repo"t/test-lib.sh test_when_finished () { · line 695
Quoted 10 lines
t/test-lib.sh +2
-4- owd=`pwd` repo="$1" mkdir -p "$repo" - cd "$repo" || error "Cannot setup test environment" + (cd "$repo" || error "Cannot setup test environment" "$GIT_EXEC_PATH/git-init" "--template=$GIT_BUILD_DIR/templates/blt/" >&3 2>&4 || error "cannot run git init -- have you built things yet?" - mv .git/hooks .git/hooks-disabled - cd "$owd" + mv .git/hooks .git/hooks-disabled)Style: why not use
Quoted 4 lines
( cd "$repo" ... ... .git/hooks-disabled )
That is a sensible suggestion, but what does "error" do?
I think you would need || exit at the end, i.e.
(
... || error "..."
) || exitor something.
Quoted 29 lines · Junio C Hamano
Quoted 20 lines · Jonathan Nieder
Quoted 7 lines · Ævar Arnfjörð Bjarmason
+++
b/t/test-lib.sht/test-lib.sh +0
-0@@ -687,14 +687,12 @@ test_when_finished () { test_create_repo () {test "$#" = 1 ||
error "bug in the test script: not 1 parameter to test-create-repo"
- owd=pwd
repo="$1"Quoted 8 lines
mkdir -p "$repo"
- cd "$repo" || error "Cannot setup test environment"
+ (cd "$repo" || error "Cannot setup test environment" "$GIT_EXEC_PATH/git-init" "--template=$GIT_BUILD_DIR/templates/blt/" >&3 2>&4 || error "cannot run git init -- have you built things yet?"
- mv .git/hooks .git/hooks-disabled
- cd "$owd"
+ mv .git/hooks .git/hooks-disabled)Style: why not use
Quoted 4 lines
(
cd "$repo" ...
... .git/hooks-disabled
)That is a sensible suggestion, but what does "error" do?
Quoted 7 lines
I think you would need || exit at the end, i.e.
(
... || error "..."
) || exitor something.
Good catch, yes. error() calls exit so this patch as-is introduces a logic error.