summaryrefslogtreecommitdiff
path: root/t
diff options
context:
space:
mode:
authorBrandon Casey <drafnel@gmail.com>2011-06-30 00:34:58 (GMT)
committerJunio C Hamano <gitster@pobox.com>2011-06-30 01:25:49 (GMT)
commit4dca1aa6502a46f8d7b6ecc8e7812c5c23ad0923 (patch)
tree18ecd42f6fabcd880b369f34802325b18707b85b /t
parent91cd7e4b426b0dc4755212fcbac3c822499ddd15 (diff)
downloadgit-4dca1aa6502a46f8d7b6ecc8e7812c5c23ad0923.zip
git-4dca1aa6502a46f8d7b6ecc8e7812c5c23ad0923.tar.gz
git-4dca1aa6502a46f8d7b6ecc8e7812c5c23ad0923.tar.bz2
git-submodule.sh: preserve stdin for the command spawned by foreach
The user-supplied command spawned by 'submodule foreach' loses its connection to the original standard input. Instead, it is connected to the output of a pipe within the git-submodule script. The user-supplied command supplied to 'submodule foreach' is spawned within a while loop which is being piped into. Due to the way shells implement piping output to a while loop, a subshell is created with its standard input attached to the output of the pipe. This results in all of the commands executed within the while loop to have their stdins modified in the same way, including the user-supplied command. This can cause a problem if the command requires reading from stdin or if it changes its behavior based on whether stdin is a tty or not. For example, this problem was noticed when trying to execute the following: git submodule foreach git shortlog --since=two.weeks.ago which printed a message about entering the first submodule and produced no further output and exited with a status of zero. In this case, shortlog detected that it was not connected to a tty, and since no revision was supplied as an argument, it attempted to read the list of revisions from standard input. Instead, it slurped up the list of submodules that was being piped to the enclosing while loop and caused that loop to end early without processing the remaining submodules. Work around this behavior by saving the original standard input file descriptor before the while loop, and restoring it when spawning the user-supplied command. This fixes the tests in t7407. Signed-off-by: Brandon Casey <drafnel@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Diffstat (limited to 't')
-rwxr-xr-xt/t7407-submodule-foreach.sh4
1 files changed, 2 insertions, 2 deletions
diff --git a/t/t7407-submodule-foreach.sh b/t/t7407-submodule-foreach.sh
index 97b7562..8a74cca 100755
--- a/t/t7407-submodule-foreach.sh
+++ b/t/t7407-submodule-foreach.sh
@@ -288,7 +288,7 @@ test_expect_success 'use "update --recursive nested1" to checkout all submodules
)
'
-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 &&
@@ -297,7 +297,7 @@ test_expect_failure 'command passed to foreach retains notion of stdin' '
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 &&