clone: bsd shell portability fix
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>
Jeff King committed
May 13, 2008 at 04:45 UTC
6d9878cc60ba97fc99aa92f40535644938cad907
1 file changed
+1
-2
git-clone.sh
+1
-2
@@ -240,7 +240,6 @@ die "working tree '$GIT_WORK_TREE' already exists."
240
D=
241
W=
242
cleanup() {
243
- err=$?
243
test -z "$D" && rm -rf "$dir"
244
test -z "$W" && test -n "$GIT_WORK_TREE" && rm -rf "$GIT_WORK_TREE"
245
cd ..
@@ -248,7 +247,7 @@ cleanup() {
247
test -n "$W" && rm -rf "$W"
248
exit $err
249
}
251
-trap cleanup 0
250
+trap 'err=$?; cleanup' 0
251
mkdir -p "$dir" && D=$(cd "$dir" && pwd) || usage
252
test -n "$GIT_WORK_TREE" && mkdir -p "$GIT_WORK_TREE" &&
253
W=$(cd "$GIT_WORK_TREE" && pwd) && GIT_WORK_TREE="$W" && export GIT_WORK_TREE