diff mbox series

[v2,1/3] doc: interpret-trailers: don’t use heredoc in examples

Message ID 38f9a4bdf89f854c30a7b708e955e2089b031c13.1680548650.git.code@khaugsbakk.name (mailing list archive)
State New, archived
Headers show
Series [v2,1/3] doc: interpret-trailers: don’t use heredoc in examples | expand

Commit Message

Kristoffer Haugsbakk April 3, 2023, 7:21 p.m. UTC
This file contains four instances of trailing spaces from its inception
in commit [1]. These spaces might be intentional, since a user would be
prompted with `> ` in an interactive session. On the one hand, this is a
whitespace error according to `git diff --check`; on the other hand, the
raw documentation—it makes no difference in the rendered output—is just
staying faithful to the simulation of the interactive prompt.

Let’s get rid of these whitespace errors and also make the examples more
friendly to cut-and-paste by replacing the heredocs with files which are
shown with cat(1).

[1]: dfd66ddf5a (Documentation: add documentation for 'git
    interpret-trailers', 2014-10-13)

Suggested-by: Junio C Hamano <gitster@pobox.com>
Cc: Christian Couder <chriscool@tuxfamily.org>
Signed-off-by: Kristoffer Haugsbakk <code@khaugsbakk.name>
---

Notes (series):
    This was one of the suggestions by Junio[1]
    
    > Showing with a separate intermediate file, i.e.
    > [snip]
    > might make the result slightly easier to follow.  I dunno.
    
    [1]: https://lore.kernel.org/git/xmqqsfdkep2b.fsf@gitster.g/

 Documentation/git-interpret-trailers.txt | 72 +++++++++++-------------
 1 file changed, 33 insertions(+), 39 deletions(-)

Comments

Junio C Hamano April 3, 2023, 8:16 p.m. UTC | #1
> @@ -357,15 +356,14 @@ Fix #42
>  $ cat ~/bin/glog-find-author
>  #!/bin/sh
>  test -n "$1" && git log --author="$1" --pretty="%an <%ae>" -1 || true
> +$ cat msg.txt
> +subject
> +
> +message

When I suggested to use "cat" to show contents, instead of
pretending an interactive session, I didn't check if we already had
examples, but it looks like we did, which is great.

> +$ cat msg.txt | git interpret-trailers --trailer="help:Junio" --trailer="help:Couder"

Do not "cat" a single file and pipe into another command.  It will
always be equivalent to redirecting that file into the command on
the downstream, i.e.

   $ git interpret-trailers --options <mst.txt

> +$ sed --in-place -e 's/ Z$/ /' commit_template.txt

Avoid "--in-place"; not everybody's "sed" has it.

Other than that, I didn't spot anything glaringly wrong.

Thanks for working on this series.
diff mbox series

Patch

diff --git a/Documentation/git-interpret-trailers.txt b/Documentation/git-interpret-trailers.txt
index 22ff3a603e..dbbb6815c3 100644
--- a/Documentation/git-interpret-trailers.txt
+++ b/Documentation/git-interpret-trailers.txt
@@ -326,13 +326,12 @@  $ git config trailer.sign.key "Signed-off-by: "
 $ git config trailer.sign.ifmissing add
 $ git config trailer.sign.ifexists doNothing
 $ git config trailer.sign.command 'echo "$(git config user.name) <$(git config user.email)>"'
-$ git interpret-trailers <<EOF
-> EOF
+$ cat empty-msg.txt | git interpret-trailers
 
 Signed-off-by: Bob <bob@example.com>
-$ git interpret-trailers <<EOF
-> Signed-off-by: Alice <alice@example.com>
-> EOF
+$ cat msg.txt
+Signed-off-by: Alice <alice@example.com>
+$ cat msg.txt | git interpret-trailers
 
 Signed-off-by: Alice <alice@example.com>
 ------------
@@ -357,15 +356,14 @@  Fix #42
 $ cat ~/bin/glog-find-author
 #!/bin/sh
 test -n "$1" && git log --author="$1" --pretty="%an <%ae>" -1 || true
+$ cat msg.txt
+subject
+
+message
 $ git config trailer.help.key "Helped-by: "
 $ git config trailer.help.ifExists "addIfDifferentNeighbor"
 $ git config trailer.help.cmd "~/bin/glog-find-author"
-$ git interpret-trailers --trailer="help:Junio" --trailer="help:Couder" <<EOF
-> subject
->
-> message
->
-> EOF
+$ cat msg.txt | git interpret-trailers --trailer="help:Junio" --trailer="help:Couder"
 subject
 
 message
@@ -382,15 +380,14 @@  Helped-by: Christian Couder <christian.couder@gmail.com>
 $ cat ~/bin/glog-grep
 #!/bin/sh
 test -n "$1" && git log --grep "$1" --pretty=reference -1 || true
+$ cat msg.txt
+subject
+
+message
 $ git config trailer.ref.key "Reference-to: "
 $ git config trailer.ref.ifExists "replace"
 $ git config trailer.ref.cmd "~/bin/glog-grep"
-$ git interpret-trailers --trailer="ref:Add copyright notices." <<EOF
-> subject
->
-> message
->
-> EOF
+$ cat msg.txt | git interpret-trailers --trailer="ref:Add copyright notices."
 subject
 
 message
@@ -402,17 +399,15 @@  Reference-to: 8bc9a0c769 (Add copyright notices., 2005-04-07)
   commit that is related, and show how it works:
 +
 ------------
+$ cat msg.txt
+subject
+
+message
 $ git config trailer.see.key "See-also: "
 $ git config trailer.see.ifExists "replace"
 $ git config trailer.see.ifMissing "doNothing"
 $ git config trailer.see.command "git log -1 --oneline --format=\"%h (%s)\" --abbrev-commit --abbrev=14 \$ARG"
-$ git interpret-trailers <<EOF
-> subject
-> 
-> message
-> 
-> see: HEAD~2
-> EOF
+$ cat msg.txt | git interpret-trailers
 subject
 
 message
@@ -427,22 +422,21 @@  See-also: fe3187489d69c4 (subject of related commit)
   to add a 'git-version' trailer:
 +
 ------------
-$ sed -e 's/ Z$/ /' >commit_template.txt <<EOF
-> ***subject***
-> 
-> ***message***
-> 
-> Fixes: Z
-> Cc: Z
-> Reviewed-by: Z
-> Signed-off-by: Z
-> EOF
+$ cat commit_template.txt
+***subject***
+
+***message***
+
+Fixes: Z
+Cc: Z
+Reviewed-by: Z
+Signed-off-by: Z
+$ sed --in-place -e 's/ Z$/ /' commit_template.txt
 $ git config commit.template commit_template.txt
-$ cat >.git/hooks/commit-msg <<EOF
-> #!/bin/sh
-> git interpret-trailers --trim-empty --trailer "git-version: \$(git describe)" "\$1" > "\$1.new"
-> mv "\$1.new" "\$1"
-> EOF
+$ cat .git/hooks/commit-msg
+#!/bin/sh
+git interpret-trailers --trim-empty --trailer "git-version: \$(git describe)" "\$1" > "\$1.new"
+mv "\$1.new" "\$1"
 $ chmod +x .git/hooks/commit-msg
 ------------