]> asedeno.scripts.mit.edu Git - git.git/commitdiff
clone: bsd shell portability fix
authorJeff King <peff@peff.net>
Tue, 13 May 2008 08:45:56 +0000 (04:45 -0400)
committerJunio C Hamano <gitster@pobox.com>
Wed, 14 May 2008 04:45:28 +0000 (21:45 -0700)
When using /bin/sh from FreeBSD 6.1, the value of $? is lost
when calling a function inside the 'trap' action. This
resulted in clone erroneously indicating success when it
should have reported failure.

As a workaround, we save the value of $? before calling any
functions.

Signed-off-by: Jeff King <peff@peff.net>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
git-clone.sh

index 9d88d1ce60d9c34bd16976d403f210fb450940a5..547228e13ce60e575d0b4a10a322edfff6c0622c 100755 (executable)
@@ -240,7 +240,6 @@ die "working tree '$GIT_WORK_TREE' already exists."
 D=
 W=
 cleanup() {
-       err=$?
        test -z "$D" && rm -rf "$dir"
        test -z "$W" && test -n "$GIT_WORK_TREE" && rm -rf "$GIT_WORK_TREE"
        cd ..
@@ -248,7 +247,7 @@ cleanup() {
        test -n "$W" && rm -rf "$W"
        exit $err
 }
-trap cleanup 0
+trap 'err=$?; cleanup' 0
 mkdir -p "$dir" && D=$(cd "$dir" && pwd) || usage
 test -n "$GIT_WORK_TREE" && mkdir -p "$GIT_WORK_TREE" &&
 W=$(cd "$GIT_WORK_TREE" && pwd) && GIT_WORK_TREE="$W" && export GIT_WORK_TREE