git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Junio C Hamano <gitster@pobox.com>
To: "Kristoffer Haugsbakk" <kristofferhaugsbakk@fastmail.com>
Cc: git@vger.kernel.org,  "Johannes Sixt" <j6t@kdbg.org>
Subject: Re: gitrevisions: be more chatty about shell metacharacter gotchas?
Date: Mon, 02 Dec 2024 10:26:22 +0900	[thread overview]
Message-ID: <xmqqttbmkh8h.fsf@gitster.g> (raw)
In-Reply-To: <702d88e9-c62d-482c-a457-6d6642e8488e@app.fastmail.com> (Kristoffer Haugsbakk's message of "Thu, 28 Nov 2024 20:30:17 +0100")

"Kristoffer Haugsbakk" <kristofferhaugsbakk@fastmail.com> writes:

> Part of why my eyes might have glazed over (I think) is that this is very
> technical phrasing.  Yes, technical phrasing in a technical manual.  To be
> expected.  But the topic is the revision syntax; all of us Git users of
> varying levels might be primed for less terse but more evident paragraphs
> like
>
>     Keep in mind that you probably should quote the search string.  A search
>     string like `:/fix nasty bug` could be interpreted as just `:/fix`
>     depending on how your shell splits words.  Try to stick to
>     `:/'fix nasty bug'` or `:/"fix nasty bug"` (whichever is better in your
>     shell) for that reason.
>
> Because this leads with what the gotcha and remedy is about.

I am very much sympathetic to the cause to help people avoid making
mistakes, and reminding of the basic rules of command line syntax
"as needed" may be a good idea.

Any arguments and options you give from the command line are subject
to the same shell quoting rules, and we at least need one single
place to say exactly that to help beginners.

On top of that, there are probably arguments and options that more
often contain shell metacharacters (like '*' and ' ') than other
arguments and options, and it may be helpful to beginners to remind
the need for quoting.  But "as needed" is relative to the level of
reader, and if we overdo it, it would make it less readable for
other readers.

There already is a note about '*'; we can add another note about
whitespace next to it, perhaps here.

 Documentation/gitcli.txt | 10 ++++++++++
 1 file changed, 10 insertions(+)

diff --git c/Documentation/gitcli.txt w/Documentation/gitcli.txt
index 7c709324ba..0a67005fc6 100644
--- c/Documentation/gitcli.txt
+++ w/Documentation/gitcli.txt
@@ -57,6 +57,16 @@ When writing a script that is expected to handle random user-input, it is
 a good practice to make it explicit which arguments are which by placing
 disambiguating `--` at appropriate places.
 
+ * Arguments, options, and option values given on the shell command
+   line follow the usual shell syntax rules.  You'd need to quote
+   your string with whitespace in it appropriately if you do not
+   want it to be split by the shell, for example.
++
+--------------------------------
+$ git commit -m "my message with whitespace"
+$ git show "HEAD^{/^my message with whitespace}"
+--------------------------------
+
  * Many commands allow wildcards in paths, but you need to protect
    them from getting globbed by the shell.  These two mean different
    things:




  reply	other threads:[~2024-12-02  1:26 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-11-28 19:30 gitrevisions: be more chatty about shell metacharacter gotchas? Kristoffer Haugsbakk
2024-12-02  1:26 ` Junio C Hamano [this message]
2024-12-02 16:17   ` Kristoffer Haugsbakk

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=xmqqttbmkh8h.fsf@gitster.g \
    --to=gitster@pobox.com \
    --cc=git@vger.kernel.org \
    --cc=j6t@kdbg.org \
    --cc=kristofferhaugsbakk@fastmail.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).