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

Re: [PATCH] doc: fix quoting bug in credential cache example

From
Junio C Hamano <gitster@pobox.com>
Date
Apr 30, 2020, 18:09 UTC
Message-ID
<xmqqr1w4sv5t.fsf@gitster.c.googlers.com>
In-Reply-To
<63f35287c9ced4d674f938bedd439aefa6c46f41.camel@gmail.com>
douglas.fuller@gmail.com writes:
> Unquoted semicolons are considered shell argument separators, quote
> them so the example works correctly.

I think what you wanted to do might make sense, but the above justification is totally incorrect.

>  # or you can specify your own shell snippet
> -!f() { echo "password=`cat $HOME/.secret`"; }; f
> +"!f() { echo password=`cat $HOME/.secret`; }; f"

This is one of the examples shown, each shows possible value that can be given to credential.helper variable. Reproducing them fully:

    # run "git credential-foo"
    foo
    # same as above, but pass an argument to the helper
    foo --bar=baz
    # the arguments are parsed by the shell, so use shell
    # quoting if necessary
    foo --bar="whitespace arg"
    # you can also use an absolute path, which will not use the git wrapper
    /path/to/my/helper --with-arguments
    # or you can specify your own shell snippet
    !f() { echo "password=`cat $HOME/.secret`"; }; f

These are examples of values, and how they may have to be quoted in various environments is not discussed here.

We will not want a patch that says that the second example is wrong because "spaces separate arguments in shell and a string with a space in it must be quoted", i.e.

    $ git -c credential.helper="foo --bar=baz" frotz
and does this
     # same as above, but pass an argument to the helper
    -foo --bar=baz
    +"foo --bar=baz"

because the quoting convention would be different depending on where it appears. In a .git/config file, i.e.

    [credential]
	helper = foo --bar=baz
is perfectly fine without quoting.
    $ git -c credential.helper='!f() { echo "password=`cat ...`"; }; f' frotz
would be how you would pass a one-shot config from shell.

Now, the reason why I said what you did is correct but the justification is wrong is because the semicolon does pose a problem in the .git/config file. In fact

    [credential]
	helper = !f() { echo "password=`cat ...`"; }; f

would *NOT* work, because semicolon introduces a comment in the configuration file.

For this particular case, you can just do
    [credential]
	helper = !echo password=`cat $HOME/.secret`
without any quoting issues, though.

Having said all that, I think we should clarify what these sample strings are in the introductory text in the examples.

I've always thought that they are illustrating possible values and how to express that value in the context the values appear in is up to the readers who learn what values to write in this document (and they learn from manual for shell to learn the shell quoting convention and manual for 'git config' to learn the config quoting convention). Hence my initial reaction to your patch was "shell? Quoting for shell is outside the scope of the explanation here".

On the other hand, for anybody who assumes that these examples are literally showing what you write after "[credential] helper = " in the configuration file, the example clearly is wrong and dq may be needed (but yours is also wrong, in that it loses double quotes around the argument to echo; if ~/.secret file had a tab in it, the helper will now yield a wrong password and you won't be able to log in).

Previous: douglas.fuller@gmail.comNext: Jeff King
Message 2 of 18 in “doc: fix quoting bug in credential cache example”
  1. doc: fix quoting bug in credential cache exampledouglas.fuller@gmail.com, Apr 30, 2020
  2. Junio C HamanoApr 30, 2020
  3. Jeff KingMay 1, 2020
  4. Jeff KingMay 1, 2020
  5. 1/2 gitcredentials(7): clarify quoting of helper examplesJeff King, May 1, 2020
  6. Andreas SchwabMay 1, 2020
  7. Jeff KingMay 1, 2020
  8. 2/2 gitcredentials(7): make shell-snippet example more realisticJeff King, May 1, 2020
  9. Junio C HamanoMay 1, 2020
  10. Jeff KingMay 1, 2020
  11. Jeff KingMay 1, 2020
  12. Jeff KingMay 1, 2020
  13. 1/2 gitcredentials(7): clarify quoting of helper examplesJeff King, May 1, 2020
  14. 2/2 gitcredentials(7): make shell-snippet example more realisticJeff King, May 1, 2020
  15. Junio C HamanoMay 1, 2020
  16. douglas.fuller@gmail.comMay 1, 2020
  17. Junio C HamanoMay 1, 2020
  18. Jeff KingMay 1, 2020

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.