toplevel=$(pwd)
 
+       # dup stdin so that it can be restored when running the external
+       # command in the subshell (and a recursive call to this function)
+       exec 3<&0
+
        module_list |
        while read mode sha1 stage path
        do
                                then
                                        cmd_foreach "--recursive" "$@"
                                fi
-                       ) ||
+                       ) <&3 3<&- ||
                        die "Stopping at '$path'; script returned non-zero status."
                fi
        done
 
        )
 '
 
-test_expect_failure 'command passed to foreach retains notion of stdin' '
+test_expect_success 'command passed to foreach retains notion of stdin' '
        (
                cd super &&
                git submodule foreach echo success >../expected &&
        test_cmp expected actual
 '
 
-test_expect_failure 'command passed to foreach --recursive retains notion of stdin' '
+test_expect_success 'command passed to foreach --recursive retains notion of stdin' '
        (
                cd clone2 &&
                git submodule foreach --recursive echo success >../expected &&