t4041 (diff-submodule-option): rewrite add_file() routine
authorRamkumar Ramachandra <artagnon@gmail.com>
Fri, 30 Nov 2012 11:37:35 +0000 (17:07 +0530)
committerJunio C Hamano <gitster@pobox.com>
Sun, 2 Dec 2012 10:02:05 +0000 (02:02 -0800)
Instead of "cd there and then come back", use the "cd there in a
subshell" pattern.  Also fix '&&' chaining in one place.

Suggested-by: Junio C Hamano <gitster@pobox.com>
Signed-off-by: Ramkumar Ramachandra <artagnon@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
t/t4041-diff-submodule-option.sh

index 08d549a7b02e65aab1912fe6e8fbc6db1494de19..de166049c23e287e26d85d42980ac3f933c5c98a 100755 (executable)
@@ -11,18 +11,18 @@ This test tries to verify the sanity of the --submodule option of git diff.
 . ./test-lib.sh
 
 add_file () {
-       sm=$1
-       shift
-       owd=$(pwd)
-       cd "$sm"
-       for name; do
-               echo "$name" > "$name" &&
-               git add "$name" &&
-               test_tick &&
-               git commit -m "Add $name"
-       done >/dev/null
-       git rev-parse --short --verify HEAD
-       cd "$owd"
+       (
+               cd "$1" &&
+               shift &&
+               for name
+               do
+                       echo "$name" >"$name" &&
+                       git add "$name" &&
+                       test_tick &&
+                       git commit -m "Add $name" || exit
+               done >/dev/null &&
+               git rev-parse --short --verify HEAD
+       )
 }
 commit_file () {
        test_tick &&