git/list[1] front-page[2] threads[3] people[4] search[5] about
 

Re: [PATCH] git submodule foreach: Skip eval for more than one argument

From
Johan Herland <johan@herland.net>
Date
Sep 27, 2013, 08:48 UTC
Message-ID
<CALKQrgfhUEE+E5KsAWbP_zj6tozk+V=qvNU1PX9Z73Vu8unTiQ@mail.gmail.com>
In-Reply-To
<alpine.DEB.2.00.1309261605330.20647@dr-wily.mit.edu>
On Thu, Sep 26, 2013 at 10:10 PM, Anders Kaseorg <andersk@mit.edu> wrote:
Show 15 quoted lines
> ‘eval "$@"’ created an extra layer of shell interpretation, which was
> probably not expected by a user who passed multiple arguments to git
> submodule foreach:
>
> $ git grep "'"
> [searches for single quotes]
> $ git submodule foreach git grep "'"
> Entering '[submodule]'
> /usr/lib/git-core/git-submodule: 1: eval: Syntax error: Unterminated quoted string
> Stopping at '[submodule]'; script returned non-zero status.
>
> To fix this, if the user passed more than one argument, just execute
> "$@" directly instead of passing it to eval.
>
> Signed-off-by: Anders Kaseorg <andersk@mit.edu>
The change looks good, and the existing tests (in t7407) pass. :-)
Two comments, however:
1. Please add the use case you mention above as a new test case, so
that we can easily catch future regressions.
2. If we are unlucky there might be existing users that work around
the existing behavior by adding an extra level of quoting (i.e. doing
the equivalent of git submodule foreach git grep "\'" in your example
above). Will their workaround break as a result of your change? Is
that acceptable?
Have fun! :)
...Johan
Show 25 quoted lines
> ---
>  git-submodule.sh | 7 ++++++-
>  1 file changed, 6 insertions(+), 1 deletion(-)
>
> diff --git a/git-submodule.sh b/git-submodule.sh
> index c17bef1..3381864 100755
> --- a/git-submodule.sh
> +++ b/git-submodule.sh
> @@ -545,7 +545,12 @@ cmd_foreach()
>                                 sm_path=$(relative_path "$sm_path") &&
>                                 # we make $path available to scripts ...
>                                 path=$sm_path &&
> -                               eval "$@" &&
> +                               if [ $# -eq 1 ]
> +                               then
> +                                       eval "$1"
> +                               else
> +                                       "$@"
> +                               fi &&
>                                 if test -n "$recursive"
>                                 then
>                                         cmd_foreach "--recursive" "$@"
> --
> 1.8.4
>
-- 
Johan Herland, <johan@herland.net>
www.herland.net
Previous: Anders KaseorgNext: Anders Kaseorg
Message 2 of 9 in “git submodule foreach: Skip eval for more than one argument”
  1. git submodule foreach: Skip eval for more than one argumentAnders Kaseorg, Sep 26, 2013
  2. Johan HerlandSep 27, 2013
  3. git submodule foreach: Skip eval for more than one argumentAnders Kaseorg, Sep 27, 2013
  4. Johan HerlandSep 27, 2013
  5. Matthijs KooijmanMar 4, 2014
  6. Johan HerlandMar 4, 2014
  7. Matthijs KooijmanMar 4, 2014
  8. Johan HerlandMar 4, 2014
  9. Matthijs KooijmanMar 4, 2014

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.