]> git.ipfire.org Git - thirdparty/git.git/blame - templates/hooks--prepare-commit-msg.sample
Merge branch 'en/merge-recursive-directory-rename-fixes'
[thirdparty/git.git] / templates / hooks--prepare-commit-msg.sample
CommitLineData
8089c85b
PB
1#!/bin/sh
2#
3# An example hook script to prepare the commit log message.
100e762a 4# Called by "git commit" with the name of the file that has the
8089c85b
PB
5# commit message, followed by the description of the commit
6# message's source. The hook's purpose is to edit the commit
7# message file. If the hook fails with a non-zero status,
8# the commit is aborted.
9#
f98f8cba 10# To enable this hook, rename this file to "prepare-commit-msg".
8089c85b 11
0ef1a4e3
KS
12# This hook includes three examples. The first one removes the
13# "# Please enter the commit message..." help message.
8089c85b 14#
0ef1a4e3 15# The second includes the output of "git diff --name-status -r"
8089c85b
PB
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#
0ef1a4e3 20# The third example adds a Signed-off-by line to the message, that can
8089c85b
PB
21# still be edited. This is rarely a good idea.
22
94eba456
KS
23COMMIT_MSG_FILE=$1
24COMMIT_SOURCE=$2
25SHA1=$3
8089c85b 26
0ef1a4e3
KS
27@PERL_PATH@ -i.bak -ne 'print unless(m/^. Please enter the commit message/..m/^#$/)' "$COMMIT_MSG_FILE"
28
94eba456 29# case "$COMMIT_SOURCE,$SHA1" in
b22a3079
KS
30# ,|template,)
31# @PERL_PATH@ -i.bak -pe '
32# print "\n" . `git diff --cached --name-status -r`
94eba456 33# if /^#/ && $first++ == 0' "$COMMIT_MSG_FILE" ;;
b22a3079
KS
34# *) ;;
35# esac
8089c85b 36
51f5a2b4 37# SOB=$(git var GIT_COMMITTER_IDENT | sed -n 's/^\(.*>\).*$/Signed-off-by: \1/p')
e1a4a283
KS
38# git interpret-trailers --in-place --trailer "$SOB" "$COMMIT_MSG_FILE"
39# if test -z "$COMMIT_SOURCE"
40# then
41# @PERL_PATH@ -i.bak -pe 'print "\n" if !$first_line++' "$COMMIT_MSG_FILE"
42# fi