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

Re: [PATCH 2/2] gitcredentials(7): make shell-snippet example more realistic

From
Junio C Hamano <gitster@pobox.com>
Date
May 1, 2020, 15:11 UTC
Message-ID
<xmqqr1w3ofko.fsf@gitster.c.googlers.com>
In-Reply-To
<20200501063513.GB26128@coredump.intra.peff.net>
Jeff King <peff@peff.net> writes:
Show 6 quoted lines
>> I can add back in the quoted \", though it does make the code slightly
>> harder to read.
>
> Or did you mean passing $1 in the test call? It definitely isn't good
> shell practice, but we know that we're getting a single-word action from
> Git, per the protocol.
I meant former.  I actually am having a second thought.

I do not think this page should be the canonical place for config and shell syntax lessons, but the value we have been using as an example is a good candidate that an end user would encounter in the real life and has need to do so.

Perhaps it deserves some comment next to it?

; For the specified site, use "your_user" as the username, and ; invoke the helper, which is a short shell script. Note that the ; value of the helper variable is enclosed in a double-quote pair, ; because it has a semicolon, which will cause the rest of the line ; discarded as a comment unless quoted. The shell script in turn ; needs to quote various pieces of it in double quotes, each of ; which needs to be escaped with a backslash.

[credential "https://example.com"]
    username = your_user
    helper = "!f() { test \"$1\" = get && echo \"password=$(cat $HOME/.secret)\"; }; f"
The more I think about it, the worse it becomes X-<

Do we expect that most of our users are comfortable editing ~/.gitconfig in their editor, or do they mostly work with the "git config --global" command?

I have a feeling that my wishful-thinking answer, which is "former", is not true in the real world. Which means they not only need to quote for the parser of the configuration file, but they then need to quote that for the shell X-<.

    $ git config --global credential.https://example.com.helper \
	'"!f() { test \"$1\" = get && echo \"password=$(cat $HOME/.secret)\"; }; f"'

I wonder if it helps the users to have something that guides them to figure out how they do the above.

Show 6 quoted lines
> Fully quoting, it looks like this:
>
>   helper = "!f() { test \"$1\" = get && echo \"password=$(cat $HOME/.secret)\"; }; f"
>
> which IMHO is getting a little hard to read. I think that's part of why
> I gave such an unfinished example in the first place. :)

Yes, "these are values, go quote them as necessary" is certainly a lot more attractive position to take. But apparently that wasn't all that helpful.

Thanks.
Previous: Jeff KingNext: douglas.fuller@gmail.com
Message 15 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.