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

[PATCH] Documentation/rev-parse: quoting is required with --parseopt

From
Thomas Rast <trast@student.ethz.ch>
Date
Jul 30, 2010, 15:01 UTC
Message-ID
<8ef69f9855ca0719c03d7dac320b3a3beb657bca.1280501949.git.trast@student.ethz.ch>
In-Reply-To
<201007301643.50730.trast@student.ethz.ch>

When calling rev-parse --parseopt, as in the (now fixed) documented example

  eval "$(echo "$OPTS_SPEC" | git rev-parse --parseopt -- "$@" || echo exit $?)"

the outermost quoting is required, as otherwise all runs of arbitrary whitespace inside the resulting 'set -- ...' call would be collapsed into a single space.

This was exposed as a result of our new use of cat <<\EOF since 47e9cd2 (parseopt: wrap rev-parse --parseopt usage for eval consumption, 2010-06-12), but has always been a problem when handling arguments containing e.g. newlines.

Point this out in the documentation, and in particular correct the example that did not have the quotes.

Noticed-by: Joshua Jensen <jjensen@workspacewhiz.com>
Signed-off-by: Thomas Rast <trast@student.ethz.ch>
---
 Documentation/git-rev-parse.txt |    7 +++++--
 1 files changed, 5 insertions(+), 2 deletions(-)
diff --git a/Documentation/git-rev-parse.txt b/Documentation/git-rev-parse.txt
index 0727f43..be4c053 100644
--- a/Documentation/git-rev-parse.txt
+++ b/Documentation/git-rev-parse.txt
@@ -184,10 +184,13 @@ scripts the same facilities C builtins have. It works as an option normalizer
 (e.g. splits single switches aggregate values), a bit like `getopt(1)` does.
 
 It takes on the standard input the specification of the options to parse and
-understand, and echoes on the standard output a line suitable for `sh(1)` `eval`
+understand, and echoes on the standard output a string suitable for `sh(1)` `eval`
 to replace the arguments with normalized ones.  In case of error, it outputs
 usage on the standard error stream, and exits with code 129.
 
+Note: Make sure you quote the result when passing it to `eval`.  See
+below for an example.
+
 Input Format
 ~~~~~~~~~~~~
 
@@ -244,7 +247,7 @@ bar=      some cool option --bar with an argument
   An option group Header
 C?        option C with an optional argument"
 
-eval `echo "$OPTS_SPEC" | git rev-parse --parseopt -- "$@" || echo exit $?`
+eval "$(echo "$OPTS_SPEC" | git rev-parse --parseopt -- "$@" || echo exit $?)"
 ------------
 
 SQ-QUOTE
-- 
1.7.2.1.342.g676a4
Previous: Thomas RastNext: Junio C Hamano
Message 6 of 7 in “git rev-parse broken on Git for Windows”
  1. Joshua JensenJul 30, 2010
  2. Johannes SchindelinJul 30, 2010
  3. Thomas RastJul 30, 2010
  4. Joshua JensenJul 30, 2010
  5. Thomas RastJul 30, 2010
  6. Documentation/rev-parse: quoting is required with --parseoptThomas Rast, Jul 30, 2010
  7. Junio C HamanoJul 30, 2010

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.