From b22a3079466b72e8a8b76065d6c28efe7eea4b16 Mon Sep 17 00:00:00 2001 From: Kaartic Sivaraam Date: Tue, 11 Jul 2017 19:41:08 +0530 Subject: hook: cleanup script Prepare the 'preare-commit-msg' sample script for upcoming changes. Preparation includes removal of an example that has outlived it's purpose. The example is the one that comments the "Conflicts:" part of a merge commit message. It isn't relevant anymore as it's done by default since 261f315b ("merge & sequencer: turn "Conflicts:" hint into a comment", 2014-08-28). Further update the relevant comments from the sample script and update the documentation. Signed-off-by: Kaartic Sivaraam Signed-off-by: Junio C Hamano --- templates/hooks--prepare-commit-msg.sample | 24 ++++++++++-------------- 1 file changed, 10 insertions(+), 14 deletions(-) (limited to 'templates') diff --git a/templates/hooks--prepare-commit-msg.sample b/templates/hooks--prepare-commit-msg.sample index 86b8f227e..279ddc1a7 100755 --- a/templates/hooks--prepare-commit-msg.sample +++ b/templates/hooks--prepare-commit-msg.sample @@ -9,28 +9,24 @@ # # 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 two examples. # -# The second includes the output of "git diff --name-status -r" +# The first includes the output of "git diff --name-status -r" # into the message, just before the "git status" output. It is # commented because it doesn't cope with --amend or with squashed # commits. # -# The third example adds a Signed-off-by line to the message, that can +# The second 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" ;; -# ,|template,) -# @PERL_PATH@ -i.bak -pe ' -# print "\n" . `git diff --cached --name-status -r` -# if /^#/ && $first++ == 0' "$1" ;; - - *) ;; -esac +# case "$2,$3" in +# ,|template,) +# @PERL_PATH@ -i.bak -pe ' +# print "\n" . `git diff --cached --name-status -r` +# if /^#/ && $first++ == 0' "$1" ;; +# *) ;; +# esac # SOB=$(git var GIT_AUTHOR_IDENT | sed -n 's/^\(.*>\).*$/Signed-off-by: \1/p') # grep -qs "^$SOB" "$1" || echo "$SOB" >> "$1" -- cgit v1.2.1 From 94eba456b4f94228f5f724ce512decb8934522c1 Mon Sep 17 00:00:00 2001 From: Kaartic Sivaraam Date: Tue, 11 Jul 2017 19:41:09 +0530 Subject: hook: name the positional variables It's always nice to have named variables instead of positional variables as they communicate their purpose well. Appropriately name the positional variables of the hook to make it easier to see what's going on. Signed-off-by: Kaartic Sivaraam Signed-off-by: Junio C Hamano --- templates/hooks--prepare-commit-msg.sample | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) (limited to 'templates') diff --git a/templates/hooks--prepare-commit-msg.sample b/templates/hooks--prepare-commit-msg.sample index 279ddc1a7..eb5912163 100755 --- a/templates/hooks--prepare-commit-msg.sample +++ b/templates/hooks--prepare-commit-msg.sample @@ -19,14 +19,17 @@ # The second example adds a Signed-off-by line to the message, that can # still be edited. This is rarely a good idea. +COMMIT_MSG_FILE=$1 +COMMIT_SOURCE=$2 +SHA1=$3 -# case "$2,$3" in +# case "$COMMIT_SOURCE,$SHA1" in # ,|template,) # @PERL_PATH@ -i.bak -pe ' # print "\n" . `git diff --cached --name-status -r` -# if /^#/ && $first++ == 0' "$1" ;; +# if /^#/ && $first++ == 0' "$COMMIT_MSG_FILE" ;; # *) ;; # esac # SOB=$(git var GIT_AUTHOR_IDENT | sed -n 's/^\(.*>\).*$/Signed-off-by: \1/p') -# grep -qs "^$SOB" "$1" || echo "$SOB" >> "$1" +# grep -qs "^$SOB" "$COMMIT_MSG_FILE" || echo "$SOB" >> "$COMMIT_MSG_FILE" -- cgit v1.2.1 From e1a4a28373befdce97daf9702f6ab790c9806451 Mon Sep 17 00:00:00 2001 From: Kaartic Sivaraam Date: Tue, 11 Jul 2017 19:41:10 +0530 Subject: hook: add sign-off using "interpret-trailers" The sample hook to prepare the commit message before a commit allows users to opt-in to add the sign-off to the commit message. The sign-off is added at a place that isn't consistent with the "-s" option of "git commit". Further, it could go out of view in certain cases. Add the sign-off in a way similar to "-s" option of "git commit" using git's interpret-trailers command. It works well in all cases except when the user invokes "git commit" without any arguments. In that case manually add a new line after the first line to ensure it's consistent with the output of "-s" option. Signed-off-by: Kaartic Sivaraam Signed-off-by: Junio C Hamano --- templates/hooks--prepare-commit-msg.sample | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) (limited to 'templates') diff --git a/templates/hooks--prepare-commit-msg.sample b/templates/hooks--prepare-commit-msg.sample index eb5912163..87d770592 100755 --- a/templates/hooks--prepare-commit-msg.sample +++ b/templates/hooks--prepare-commit-msg.sample @@ -32,4 +32,8 @@ SHA1=$3 # esac # SOB=$(git var GIT_AUTHOR_IDENT | sed -n 's/^\(.*>\).*$/Signed-off-by: \1/p') -# grep -qs "^$SOB" "$COMMIT_MSG_FILE" || echo "$SOB" >> "$COMMIT_MSG_FILE" +# git interpret-trailers --in-place --trailer "$SOB" "$COMMIT_MSG_FILE" +# if test -z "$COMMIT_SOURCE" +# then +# @PERL_PATH@ -i.bak -pe 'print "\n" if !$first_line++' "$COMMIT_MSG_FILE" +# fi -- cgit v1.2.1 From 0ef1a4e32a720928a497a13ef08aa8f0a63dc476 Mon Sep 17 00:00:00 2001 From: Kaartic Sivaraam Date: Tue, 11 Jul 2017 20:00:54 +0530 Subject: hook: add a simple first example Add a simple example that replaces an outdated example that was removed. This ensures that there's at the least a simple example that illustrates what could be done using the hook just by enabling it. Also, update the documentation. Signed-off-by: Kaartic Sivaraam Signed-off-by: Junio C Hamano --- templates/hooks--prepare-commit-msg.sample | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) (limited to 'templates') diff --git a/templates/hooks--prepare-commit-msg.sample b/templates/hooks--prepare-commit-msg.sample index 87d770592..dc707e46e 100755 --- a/templates/hooks--prepare-commit-msg.sample +++ b/templates/hooks--prepare-commit-msg.sample @@ -9,20 +9,23 @@ # # To enable this hook, rename this file to "prepare-commit-msg". -# This hook includes two examples. +# This hook includes three examples. The first one removes the +# "# Please enter the commit message..." help message. # -# The first includes the output of "git diff --name-status -r" +# The second includes the output of "git diff --name-status -r" # into the message, just before the "git status" output. It is # commented because it doesn't cope with --amend or with squashed # commits. # -# The second example adds a Signed-off-by line to the message, that can +# The third example adds a Signed-off-by line to the message, that can # still be edited. This is rarely a good idea. COMMIT_MSG_FILE=$1 COMMIT_SOURCE=$2 SHA1=$3 +@PERL_PATH@ -i.bak -ne 'print unless(m/^. Please enter the commit message/..m/^#$/)' "$COMMIT_MSG_FILE" + # case "$COMMIT_SOURCE,$SHA1" in # ,|template,) # @PERL_PATH@ -i.bak -pe ' -- cgit v1.2.1