Skip to content

Commit 91cd7e4

Browse files
drafnelgitster
authored andcommitted
t/t7407: demonstrate that the command called by 'submodule foreach' loses stdin
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. 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 (e.g. git shortlog). Demonstrate this flaw. Signed-off-by: Brandon Casey <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 98dbe63 commit 91cd7e4

File tree

1 file changed

+18
-0
lines changed

1 file changed

+18
-0
lines changed

t/t7407-submodule-foreach.sh

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -288,4 +288,22 @@ test_expect_success 'use "update --recursive nested1" to checkout all submodules
288288
)
289289
'
290290

291+
test_expect_failure 'command passed to foreach retains notion of stdin' '
292+
(
293+
cd super &&
294+
git submodule foreach echo success >../expected &&
295+
yes | git submodule foreach "read y && test \"x\$y\" = xy && echo success" >../actual
296+
) &&
297+
test_cmp expected actual
298+
'
299+
300+
test_expect_failure 'command passed to foreach --recursive retains notion of stdin' '
301+
(
302+
cd clone2 &&
303+
git submodule foreach --recursive echo success >../expected &&
304+
yes | git submodule foreach --recursive "read y && test \"x\$y\" = xy && echo success" >../actual
305+
) &&
306+
test_cmp expected actual
307+
'
308+
291309
test_done

0 commit comments

Comments
 (0)