Merge branch 'bc/submodule-foreach-stdin-fix-1.7.4' into maint
authorJunio C Hamano <gitster@pobox.com>
Tue, 16 Aug 2011 18:23:26 +0000 (11:23 -0700)
committerJunio C Hamano <gitster@pobox.com>
Tue, 16 Aug 2011 18:23:26 +0000 (11:23 -0700)
* bc/submodule-foreach-stdin-fix-1.7.4:
git-submodule.sh: preserve stdin for the command spawned by foreach
t/t7407: demonstrate that the command called by 'submodule foreach' loses stdin

git-submodule.sh
t/t7407-submodule-foreach.sh
index d189a24c71c44806a9c1381e2a8e5993269e568a..9c6dca5a1590a22ec7478e46b7d4660c7d1beb01 100755 (executable)
@@ -300,6 +300,10 @@ cmd_foreach()
 
        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
@@ -316,7 +320,7 @@ cmd_foreach()
                                then
                                        cmd_foreach "--recursive" "$@"
                                fi
-                       ) ||
+                       ) <&3 3<&- ||
                        die "Stopping at '$path'; script returned non-zero status."
                fi
        done
index e5be13c271c92ce7c51601ee1eaf966d849d8ae4..835a50624114253b634896e1cceae43578a279bf 100755 (executable)
@@ -292,4 +292,22 @@ test_expect_success 'use "update --recursive nested1" to checkout all submodules
        )
 '
 
+test_expect_success 'command passed to foreach retains notion of stdin' '
+       (
+               cd super &&
+               git submodule foreach echo success >../expected &&
+               yes | git submodule foreach "read y && test \"x\$y\" = xy && echo success" >../actual
+       ) &&
+       test_cmp expected actual
+'
+
+test_expect_success 'command passed to foreach --recursive retains notion of stdin' '
+       (
+               cd clone2 &&
+               git submodule foreach --recursive echo success >../expected &&
+               yes | git submodule foreach --recursive "read y && test \"x\$y\" = xy && echo success" >../actual
+       ) &&
+       test_cmp expected actual
+'
+
 test_done