Skip to content

Commit

Permalink
Merge branch 'ak/submodule-foreach-quoting'
Browse files Browse the repository at this point in the history
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
  • Loading branch information
Junio C Hamano committed Dec 5, 2013
2 parents daad3aa + 1c4fb13 commit b2a0afd
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 1 deletion.
7 changes: 6 additions & 1 deletion git-submodule.sh
Original file line number Diff line number Diff line change
Expand Up @@ -545,7 +545,12 @@ cmd_foreach()
sm_path=$(relative_path "$sm_path") &&
# we make $path available to scripts ...
path=$sm_path &&
eval "$@" &&
if test $# -eq 1
then
eval "$1"
else
"$@"
fi &&
if test -n "$recursive"
then
cmd_foreach "--recursive" "$@"
Expand Down
9 changes: 9 additions & 0 deletions t/t7407-submodule-foreach.sh
Original file line number Diff line number Diff line change
Expand Up @@ -325,4 +325,13 @@ test_expect_success 'command passed to foreach --recursive retains notion of std
test_cmp expected actual
'

test_expect_success 'multi-argument command passed to foreach is not shell-evaluated twice' '
(
cd super &&
git submodule foreach "echo \\\"quoted\\\"" > ../expected &&
git submodule foreach echo \"quoted\" > ../actual
) &&
test_cmp expected actual
'

test_done

0 comments on commit b2a0afd

Please sign in to comment.