aboutsummaryrefslogtreecommitdiff
path: root/contrib/conf/prepare-commit-msg
blob: a95f29430545fdd5ecf6ee3f6332af67292545ed (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
#!/bin/bash

# use as .git/hooks/pre-commit

COMMIT_MSG_FILE=$1
COMMIT_SOURCE=$2
SHA1=$3

exec 1>&2

RET=0
changed=$(git diff --cached --name-only)

for f in $changed;
do
 # Only headers in include
 if echo $f | grep \src\/include\/.\*\.h\$  > /dev/null
 then
    RET=1
 fi
done

# Only add custom message when there is no commit source
# ($COMMIT_SOURCE is empty). Otherwise, keep the default message
# proposed by Git. Possible commit source: message, template,
# merge, squash or commit.
if [ -z "$COMMIT_SOURCE" ];
then
  hint=$(cat "$COMMIT_MSG_FILE")
  echo -e "# Our commit subject format policy is:\n# <subsystem>: <description>\n# Adding 'Issue #1234'/'Fixes #1234' into the description will automatically update/resolve issue #1234 in mantis." > "$COMMIT_MSG_FILE"
  if [ $RET = 1 ];
  then
    echo -e "# Your commit includes staged changes that indicate an API change which requires a NEWS line." >> "$COMMIT_MSG_FILE"
  fi
  echo "$hint" >> "$COMMIT_MSG_FILE"
fi
exit 0