hg-fast-export.sh: Do not ignore hg-fast-export.py exit code
authorKyle J. McKay <mackyle@gmail.com>
Sat, 15 Mar 2014 04:02:26 +0000 (14 21:02 -0700)
committerFrej Drejhammar <frej.drejhammar@gmail.com>
Sun, 16 Mar 2014 15:00:42 +0000 (16 16:00 +0100)
Originally 9643aa5d did this by using a bashism even though the
/bin/sh interpreter is being used.

Then ea55929e attempted to compensate for this by disabling the
bashism when the interpreter was not actually bash which results
in the hg-fast-export.py exit code still being ignored in that case.

Instead check the error code without requiring a bashism.

hg-fast-export.sh

index 6adbab0..f6565d0 100755 (executable)
@@ -81,14 +81,32 @@ fi
 # cleanup on exit
 trap 'rm -f "$GIT_DIR/$PFX-$SFX_MARKS.old" "$GIT_DIR/$PFX-$SFX_MARKS.tmp"' 0
 
-GIT_DIR="$GIT_DIR" $PYTHON "$ROOT/hg-fast-export.py" \
-  --repo "$REPO" \
-  --marks "$GIT_DIR/$PFX-$SFX_MARKS" \
-  --mapping "$GIT_DIR/$PFX-$SFX_MAPPING" \
-  --heads "$GIT_DIR/$PFX-$SFX_HEADS" \
-  --status "$GIT_DIR/$PFX-$SFX_STATE" \
-  "$@" \
-| git fast-import $GFI_OPTS --export-marks="$GIT_DIR/$PFX-$SFX_MARKS.tmp" || exit 1
+_err1=
+_err2=
+exec 3>&1
+{ read -r _err1 || :; read -r _err2 || :; } <<-EOT
+$(
+  exec 4>&3 3>&1 1>&4 4>&-
+  {
+    _e1=0
+    GIT_DIR="$GIT_DIR" $PYTHON "$ROOT/hg-fast-export.py" \
+      --repo "$REPO" \
+      --marks "$GIT_DIR/$PFX-$SFX_MARKS" \
+      --mapping "$GIT_DIR/$PFX-$SFX_MAPPING" \
+      --heads "$GIT_DIR/$PFX-$SFX_HEADS" \
+      --status "$GIT_DIR/$PFX-$SFX_STATE" \
+      "$@" 3>&- || _e1=$?
+    echo $_e1 >&3
+  } | \
+  {
+    _e2=0
+    git fast-import $GFI_OPTS --export-marks="$GIT_DIR/$PFX-$SFX_MARKS.tmp" 3>&- || _e2=$?
+    echo $_e2 >&3
+  }
+)
+EOT
+exec 3>&-
+[ "$_err1" = 0 -a "$_err2" = 0 ] || exit 1
 
 # move recent marks cache out of the way...
 if [ -f "$GIT_DIR/$PFX-$SFX_MARKS" ] ; then