git@vger.kernel.org mailing list mirror (one of many)
 help / color / mirror / code / Atom feed
From: Junio C Hamano <gitster@pobox.com>
To: Kaartic Sivaraam <kaarticsivaraam91196@gmail.com>
Cc: git@vger.kernel.org
Subject: Re: [PATCH 1/2] hooks: replace irrelevant hook sample
Date: Fri, 07 Jul 2017 11:27:56 -0700	[thread overview]
Message-ID: <xmqqinj4ayqb.fsf@gitster.mtv.corp.google.com> (raw)
In-Reply-To: <20170707160740.9748-1-kaarticsivaraam91196@gmail.com> (Kaartic Sivaraam's message of "Fri, 7 Jul 2017 21:37:39 +0530")

Kaartic Sivaraam <kaarticsivaraam91196@gmail.com> writes:

> The pre-commit-msg hook sample has an example that comments
> the "Conflicts:" part of the merge commmit. It isn't relevant
> anymore as it's done by default since 261f315b ("merge & sequencer:
> turn "Conflicts:" hint into a comment", 2014-08-28).
>
> Add an alternative example that replaces it. This ensures there's
> at the least a simple example that illustrates what could be done
> using the hook just by enabling it.
>
> Signed-off-by: Kaartic Sivaraam <kaarticsivaraam91196@gmail.com>
> ---
>  I have made the second patch depend on the first one to avoid
>  conflicts that may occur. Further, it was meaningful to join
>  the two patches as they would go together (or) not at all.

Whether the two samples these patches implement are useful ones or
not, the early part of 2/2 that starts using named variables instead
of positional ones is an improvement.  It makes it easier to see
what is going on.

Patch 2/2 as posted forgets to update some references to $1, $2 and
$3, both in the actual code and also commented out part, e.g.

    sed -e ... "$COMMIT_MSG_FILE" >"$SED_OUTPUT_TEMP" && mv "$SED_OUTPUT_TEMP" "$1"
    # case "$2,$3" in

In the first one, $COMMIT_MSG_FILE and $1 refer to the same thing;
they should be consistent.

If these updates were to be done as multiple patches, the change to
use named not positional variables, without changing anything else,
should come second, I think, after the one that simply removes the
now-useless "Conflicts:" sample from the script, as a preparatory
clean-up step.  You can build other things like hints-removal and
sign-off with interpret-trailers on top of these two steps.

Have you considered using "@PERL_PATH@ -i" instead of "sed" in this
step, by the way?  That would allow you not to worry about the
temporary file left behind (e.g. what happens when somebody else
runs this in a shared repository setting, creating and leaving the
temporary file that you may not be able to write into later because
her umask is tighter, and then you try to make a commit).

Thanks.

>  templates/hooks--prepare-commit-msg.sample | 16 ++++++++--------
>  1 file changed, 8 insertions(+), 8 deletions(-)
>
> diff --git a/templates/hooks--prepare-commit-msg.sample b/templates/hooks--prepare-commit-msg.sample
> index 86b8f227e..5a638ebda 100755
> --- a/templates/hooks--prepare-commit-msg.sample
> +++ b/templates/hooks--prepare-commit-msg.sample
> @@ -9,8 +9,9 @@
>  #
>  # To enable this hook, rename this file to "prepare-commit-msg".
>  
> -# This hook includes three examples.  The first comments out the
> -# "Conflicts:" part of a merge commit.
> +# This hook includes three examples.  The first one removes three
> +# comment lines starting from the line that has the words
> +# "# Please enter the" in it's beginning.
>  #
>  # The second includes the output of "git diff --name-status -r"
>  # into the message, just before the "git status" output.  It is
> @@ -20,17 +21,16 @@
>  # The third example adds a Signed-off-by line to the message, that can
>  # still be edited.  This is rarely a good idea.
>  
> -case "$2,$3" in
> -  merge,)
> -    @PERL_PATH@ -i.bak -ne 's/^/# /, s/^# #/#/ if /^Conflicts/ .. /#/; print' "$1" ;;
> +sed -e '/^. Please enter the commit message /,/^#$/d' "$1" >'.sed-output.temp' && mv '.sed-output.temp' "$1"
>  
> +# case "$2,$3" in
>  # ,|template,)
>  #   @PERL_PATH@ -i.bak -pe '
>  #      print "\n" . `git diff --cached --name-status -r`
>  #	 if /^#/ && $first++ == 0' "$1" ;;
> -
> -  *) ;;
> -esac
> +#
> +#  *) ;;
> +# esac
>  
>  # SOB=$(git var GIT_AUTHOR_IDENT | sed -n 's/^\(.*>\).*$/Signed-off-by: \1/p')
>  # grep -qs "^$SOB" "$1" || echo "$SOB" >> "$1"

  parent reply	other threads:[~2017-07-07 18:28 UTC|newest]

Thread overview: 58+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-06-30 15:43 [PATCH] hooks: add signature to the top of the commit message Kaartic Sivaraam
2017-06-30 16:44 ` Junio C Hamano
2017-07-01 14:15   ` Kaartic Sivaraam
2017-07-01 16:16     ` "git intepret-trailers" vs. "sed script" to add the signature Kaartic Sivaraam
2017-07-01 17:32       ` [PATCH/RFC] hooks: add signature using "interpret-trailers" Kaartic Sivaraam
2017-07-03 16:58       ` "git intepret-trailers" vs. "sed script" to add the signature Junio C Hamano
2017-07-04 19:16         ` Kaartic Sivaraam
2017-07-05  1:48           ` Junio C Hamano
2017-07-05 17:00           ` [PATCH] hooks: add signature using "interpret-trailers" Kaartic Sivaraam
2017-07-05 17:35             ` Kaartic Sivaraam
2017-07-05 19:37               ` Junio C Hamano
2017-07-05 20:14               ` Ramsay Jones
2017-07-06 14:30                 ` Kaartic Sivaraam
2017-07-01 17:36     ` [PATCH] hooks: add signature to the top of the commit message Junio C Hamano
2017-07-01 18:40       ` Philip Oakley
2017-07-01 20:28         ` Junio C Hamano
2017-07-01 21:00           ` Philip Oakley
2017-07-01 18:52       ` Kaartic Sivaraam
2017-07-01 20:31         ` Junio C Hamano
2017-07-02 11:19           ` Kaartic Sivaraam
2017-07-02 11:27             ` [PATCH/RFC] hooks: replace irrelevant hook sample Kaartic Sivaraam
2017-07-05 16:51               ` [PATCH] " Kaartic Sivaraam
2017-07-05 19:50                 ` Junio C Hamano
2017-07-07 11:53                   ` Kaartic Sivaraam
2017-07-07 15:05                     ` Junio C Hamano
2017-07-07 15:24                       ` Kaartic Sivaraam
2017-07-07 16:07                         ` [PATCH 1/2] " Kaartic Sivaraam
2017-07-07 16:07                           ` [PATCH 2/2] hooks: add signature using "interpret-trailers" Kaartic Sivaraam
2017-07-07 18:27                           ` Junio C Hamano [this message]
2017-07-10 14:17                             ` [PATCH 1/4] hook: cleanup script Kaartic Sivaraam
2017-07-10 14:17                               ` [PATCH 2/4] hook: name the positional variables Kaartic Sivaraam
2017-07-10 19:51                                 ` Junio C Hamano
2017-07-10 14:17                               ` [PATCH 3/4] hook: add signature using "interpret-trailers" Kaartic Sivaraam
2017-07-10 15:13                                 ` Ramsay Jones
2017-07-10 19:53                                   ` Junio C Hamano
2017-07-11 14:11                                     ` [PATCH 1/4] hook: cleanup script Kaartic Sivaraam
2017-07-11 14:11                                       ` [PATCH 2/4] hook: name the positional variables Kaartic Sivaraam
2017-07-11 14:11                                       ` [PATCH 3/4] hook: add sign-off using "interpret-trailers" Kaartic Sivaraam
2017-08-14  8:46                                         ` [PATCH] hook: use correct logical variable Kaartic Sivaraam
2017-08-14 17:54                                           ` Stefan Beller
2017-08-14 18:19                                           ` Junio C Hamano
2017-08-15  9:31                                             ` Kaartic Sivaraam
2017-08-15 17:28                                               ` Junio C Hamano
2017-08-17  2:47                                                 ` Kaartic Sivaraam
2017-08-17  2:50                                                   ` [PATCH v2/RFC] " Kaartic Sivaraam
2017-08-15  9:32                                             ` [PATCH] " Kaartic Sivaraam
2017-07-11 14:11                                       ` [PATCH 4/4] hook: add a simple first example Kaartic Sivaraam
2017-07-11 14:30                                         ` Kaartic Sivaraam
2017-07-11 13:10                                   ` [PATCH 3/4] hook: add signature using "interpret-trailers" Kaartic Sivaraam
2017-07-11 13:18                                   ` Kaartic Sivaraam
2017-07-10 14:17                               ` [PATCH 4/4] hook: add a simple first example Kaartic Sivaraam
2017-07-10 20:02                                 ` Junio C Hamano
2017-07-11 13:29                                   ` Kaartic Sivaraam
2017-07-11 16:03                                     ` Junio C Hamano
2017-07-11 18:04                                       ` Kaartic Sivaraam
2017-07-11 18:06                                       ` Kaartic Sivaraam
2017-07-10 19:50                               ` [PATCH 1/4] hook: cleanup script Junio C Hamano
2017-07-02 11:29             ` [PATCH] hooks: add script to HOOKS that allows adding notes from commit message Kaartic Sivaraam

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

  List information: http://vger.kernel.org/majordomo-info.html

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

  git send-email \
    --in-reply-to=xmqqinj4ayqb.fsf@gitster.mtv.corp.google.com \
    --to=gitster@pobox.com \
    --cc=git@vger.kernel.org \
    --cc=kaarticsivaraam91196@gmail.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.
Code repositories for project(s) associated with this public inbox

	https://80x24.org/mirrors/git.git

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 read-only IMAP folder(s) and NNTP newsgroup(s).