Skip to content

Commit 13ac90a

Browse files
committed
Merge branch 'bc/submodule-foreach-stdin-fix-1.7.4'
* 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 Conflicts: git-submodule.sh
2 parents 0e8a23b + 4dca1aa commit 13ac90a

File tree

2 files changed

+23
-1
lines changed

2 files changed

+23
-1
lines changed

git-submodule.sh

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -304,6 +304,10 @@ cmd_foreach()
304304

305305
toplevel=$(pwd)
306306

307+
# dup stdin so that it can be restored when running the external
308+
# command in the subshell (and a recursive call to this function)
309+
exec 3<&0
310+
307311
module_list |
308312
while read mode sha1 stage path
309313
do
@@ -320,7 +324,7 @@ cmd_foreach()
320324
then
321325
cmd_foreach "--recursive" "$@"
322326
fi
323-
) ||
327+
) <&3 3<&- ||
324328
die "$(eval_gettext "Stopping at '\$path'; script returned non-zero status.")"
325329
fi
326330
done

t/t7407-submodule-foreach.sh

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -292,4 +292,22 @@ test_expect_success 'use "update --recursive nested1" to checkout all submodules
292292
)
293293
'
294294

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

0 commit comments

Comments
 (0)