aboutsummaryrefslogtreecommitdiff
blob: ab01f49b5ad03f64ec892ed7f8295166e84da5b2 (plain)
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
38
39
40
41
#!/bin/sh
#
# A hook to add [$branch] to the beginning of a commit message
# if certain conditions are met.
#
# This is a prepare-commit-msg hook.
#
# To install this you can either copy or symlink it to
# $GIT_DIR/hooks, example:
#
# ln -s ../../git-tools/hooks/prepare-commit-msg \\
#   .git/hooks/prepare-commit-msg

# get branch name
branch="$(git symbolic-ref HEAD)"

# exit if no branch name is present
# (eg. detached HEAD)
if [ $? -ne 0 ]
then
	exit
fi

# strip off refs/heads/
branch="$(echo "$branch" | sed "s/refs\/heads\///g")"

# add [branchname] to commit message
# * only run when normal commit is made (without -m or -F;
#   not a merge, etc.)
# * also make sure the branch name begins with bug/ or feature/
if [ "$2" = "" ]
then
	echo "[$branch] $(cat "$1")" > "$1"
fi

if (echo $branch | grep '^ticket/')
then
	ticket_id="$(echo $branch | sed "s/ticket\///g")"
	echo >> "$1"
	echo "PHPBB3-$ticket_id" >> "$1"
fi