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 <kaarticsivaraam91196@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Kaartic Sivaraam committed
Jul 11, 2017 at 20:00 UTC
0ef1a4e32a720928a497a13ef08aa8f0a63dc476
2 files changed
+9
-3
Documentation/githooks.txt
+3
@@ -121,6 +121,9 @@ it is not suppressed by the `--no-verify` option. A non-zero exit
121
means a failure of the hook and aborts the commit. It should not
122
be used as replacement for pre-commit hook.
123
124
+The sample `prepare-commit-msg` hook that comes with Git removes the
125
+help message found in the commented portion of the commit template.
126
+
127
commit-msg
128
~~~~~~~~~~
129
templates/hooks--prepare-commit-msg.sample
+6
-3
@@ -9,20 +9,23 @@
9
#
10
# To enable this hook, rename this file to "prepare-commit-msg".
11
12
-# This hook includes two examples.
12
+# This hook includes three examples. The first one removes the
13
+# "# Please enter the commit message..." help message.
14
#
14
-# The first includes the output of "git diff --name-status -r"
15
+# The second includes the output of "git diff --name-status -r"
16
# into the message, just before the "git status" output. It is
17
# commented because it doesn't cope with --amend or with squashed
18
# commits.
19
#
19
-# The second example adds a Signed-off-by line to the message, that can
20
+# The third example adds a Signed-off-by line to the message, that can
21
# still be edited. This is rarely a good idea.
22
23
COMMIT_MSG_FILE=$1
24
COMMIT_SOURCE=$2
25
SHA1=$3
26
27
+@PERL_PATH@ -i.bak -ne 'print unless(m/^. Please enter the commit message/..m/^#$/)' "$COMMIT_MSG_FILE"
28
+
29
# case "$COMMIT_SOURCE,$SHA1" in
30
# ,|template,)
31
# @PERL_PATH@ -i.bak -pe '