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 <kaarticsivaraam91196@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Kaartic Sivaraam committed
Jul 11, 2017 at 19:41 UTC
e1a4a28373befdce97daf9702f6ab790c9806451
1 file changed
+5
-1
templates/hooks--prepare-commit-msg.sample
+5
-1
@@ -32,4 +32,8 @@ SHA1=$3
32
# esac
33
34
# SOB=$(git var GIT_AUTHOR_IDENT | sed -n 's/^\(.*>\).*$/Signed-off-by: \1/p')
35
-# grep -qs "^$SOB" "$COMMIT_MSG_FILE" || echo "$SOB" >> "$COMMIT_MSG_FILE"
35
+# git interpret-trailers --in-place --trailer "$SOB" "$COMMIT_MSG_FILE"
36
+# if test -z "$COMMIT_SOURCE"
37
+# then
38
+# @PERL_PATH@ -i.bak -pe 'print "\n" if !$first_line++' "$COMMIT_MSG_FILE"
39
+# fi