Skip to content

Commit d5c756e

Browse files
committed
Merge branch 'bc/submodule-foreach-stdin-fix-1.7.4' into maint
* 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
2 parents 824f4a9 + 4dca1aa commit d5c756e

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
@@ -300,6 +300,10 @@ cmd_foreach()
300300

301301
toplevel=$(pwd)
302302

303+
# dup stdin so that it can be restored when running the external
304+
# command in the subshell (and a recursive call to this function)
305+
exec 3<&0
306+
303307
module_list |
304308
while read mode sha1 stage path
305309
do
@@ -316,7 +320,7 @@ cmd_foreach()
316320
then
317321
cmd_foreach "--recursive" "$@"
318322
fi
319-
) ||
323+
) <&3 3<&- ||
320324
die "Stopping at '$path'; script returned non-zero status."
321325
fi
322326
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)