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

Re: [msysGit] git rev-parse broken on Git for Windows

From
Thomas Rast <trast@student.ethz.ch>
Date
Jul 30, 2010, 14:43 UTC
Message-ID
<201007301643.50730.trast@student.ethz.ch>
In-Reply-To
<4C52E125.1020004@workspacewhiz.com>
Joshua Jensen wrote:
Show 20 quoted lines
> Thomas Rast wrote:
> > Johannes Schindelin wrote:
> >>> eval $(echo "$OPTS_SPEC" | git rev-parse --parseopt -- "$@" || echo exit $?)
> > Can you elaborate on "break"?
> >
> > Because as you can see in git-sh-setup.sh, the "official" user of
> > parseopt does
> >
> > 	eval "$(
> > 		echo "$OPTIONS_SPEC" |
> > 			git rev-parse --parseopt $parseopt_extra -- "$@" ||
> > 		echo exit $?
> > 	)"
> >
> > So AFAICS they only differ in the quoting.  And the latter works.
> Here is the output from Git Bash:
> 
> $ git subtree
> C:\Program Files (x86)\Git/libexec/git-core/git-subtree: eval: line 31: 
> syntax error near unexpected token `<'
[...]
> The example from the git rev-parse documentation fails in the same way:
> 
> eval `echo "$OPTS_SPEC" | git rev-parse --parseopt $parseopt_extra -- 
> "$@" || echo exit $?`

Oh, sorry that I was so dense in the first reply. Of course the quoting is the problem. When unquoted, the shell first splits along whitespace and then eval reassembles with *one space* between each pair of words. The change just exacerbated the issue; there are other ways to trigger bad behaviour if the eval uses an unquoted --parseopt:

  # what you saw
  $ echo eval $( (echo 'description'; echo --; echo "s,long= foo") | git rev-parse --parseopt -- --help || echo exit $?)
  eval cat <<\EOF usage: description -s, --long ... foo EOF exit 129
  # newlines are clobbered
  $ echo eval $( (echo 'description'; echo --; echo "s,long= foo") | git rev-parse --parseopt -- --long="$(printf 'argument\nwith\nnewlines')" || echo exit $?)
  eval set -- -s 'argument with newlines' --
  # consecutive spaces are also clobbered
  echo eval $( (echo 'description'; echo --; echo "s,long= foo") | git rev-parse --parseopt -- --long="three   spaces" || echo exit $?)
  eval set -- -s 'three spaces' --

So I'm afraid Avery will have to fix this in git-subtree. I'll also follow up with a doc patch for git-rev-parse. Luckily there are no users in git outside of tests and git-sh-setup, so there are no bugs.

-- 
Thomas Rast
trast@{inf,student}.ethz.ch
Previous: Joshua JensenNext: Thomas Rast
Message 5 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.