Skip to content

Commit b2a0afd

Browse files
committed
Merge branch 'ak/submodule-foreach-quoting'
A behavior change, but a worthwhile one: "git submodule foreach" was treating its arguments as part of a single command to be concatenated and passed to a shell, making writing buggy scripts too easy. This patch preserves the old "just pass it to the shell" behavior when a single argument is passed to 'git submodule foreach' and moves to a new "skip the shell and use the arguments passed unmolested" behavior when more than one argument is passed. The old behavior (always concatenating and passing to the shell) was similar to the 'ssh' command, while the new behavior (switching on the number of arguments) is what 'xterm -e' does. May need more thought to make sure this change is advertised well so that scripts that used multiple arguments but added their own extra layer of quoting are not broken. * ak/submodule-foreach-quoting: submodule foreach: skip eval for more than one argument
2 parents daad3aa + 1c4fb13 commit b2a0afd

File tree

2 files changed

+15
-1
lines changed

2 files changed

+15
-1
lines changed

git-submodule.sh

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -545,7 +545,12 @@ cmd_foreach()
545545
sm_path=$(relative_path "$sm_path") &&
546546
# we make $path available to scripts ...
547547
path=$sm_path &&
548-
eval "$@" &&
548+
if test $# -eq 1
549+
then
550+
eval "$1"
551+
else
552+
"$@"
553+
fi &&
549554
if test -n "$recursive"
550555
then
551556
cmd_foreach "--recursive" "$@"

t/t7407-submodule-foreach.sh

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -325,4 +325,13 @@ test_expect_success 'command passed to foreach --recursive retains notion of std
325325
test_cmp expected actual
326326
'
327327

328+
test_expect_success 'multi-argument command passed to foreach is not shell-evaluated twice' '
329+
(
330+
cd super &&
331+
git submodule foreach "echo \\\"quoted\\\"" > ../expected &&
332+
git submodule foreach echo \"quoted\" > ../actual
333+
) &&
334+
test_cmp expected actual
335+
'
336+
328337
test_done

0 commit comments

Comments
 (0)