The sample hook to prepare the commit message before a commit allows users to opt-in to add the signature to the commit message. The signature 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 signature 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. While at it, name the input parameters to improve readability of script. Signed-off-by: Kaartic Sivaraam <kaarticsivaraam91196@xxxxxxxxx> --- templates/hooks--prepare-commit-msg.sample | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/templates/hooks--prepare-commit-msg.sample b/templates/hooks--prepare-commit-msg.sample index 5a638ebda..7495078cb 100755 --- a/templates/hooks--prepare-commit-msg.sample +++ b/templates/hooks--prepare-commit-msg.sample @@ -21,7 +21,12 @@ # The third example adds a Signed-off-by line to the message, that can # still be edited. This is rarely a good idea. -sed -e '/^. Please enter the commit message /,/^#$/d' "$1" >'.sed-output.temp' && mv '.sed-output.temp' "$1" +COMMIT_MSG_FILE=$1 +COMMIT_SOURCE=$2 +SHA1=$3 + +SED_OUTPUT_TEMP='.sed-output-temp' +sed -e '/^. Please enter the commit message /,/^#$/d' "$COMMIT_MSG_FILE" >"$SED_OUTPUT_TEMP" && mv "$SED_OUTPUT_TEMP" "$1" # case "$2,$3" in # ,|template,) @@ -32,5 +37,14 @@ sed -e '/^. Please enter the commit message /,/^#$/d' "$1" >'.sed-output.temp' & # *) ;; # esac +# TEMP_FILE='.template-temp' # SOB=$(git var GIT_AUTHOR_IDENT | sed -n 's/^\(.*>\).*$/Signed-off-by: \1/p') -# grep -qs "^$SOB" "$1" || echo "$SOB" >> "$1" +# git interpret-trailers --in-place --trailer "$SOB" "$COMMIT_MSG_FILE" +# if test -z "$COMMIT_SOURCE" +# then +# { +# echo +# cat "$COMMIT_MSG_FILE" +# } >"$TEMP_FILE" +# mv "$TEMP_FILE" "$COMMIT_MSG_FILE" +# fi -- 2.13.2.879.g2ab69f31a.dirty