-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path.prepare-commit-msg
More file actions
executable file
·31 lines (27 loc) · 947 Bytes
/
.prepare-commit-msg
File metadata and controls
executable file
·31 lines (27 loc) · 947 Bytes
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
#!/bin/sh
# Put this file in .git/hooks/prepare-commit-msg
# This script prepares the commit message by inserting
# [PROJECT_NAME] (BRANCH) at the top of the message.
# PROJECT_NAME is your own environment variable,
# you can set it like this:
# $ export PROJECT_NAME=MY_PROJECT_NAME
# or don't set it, you'll just have empty brackets.
# Then you just have to write the commit message.
current_branch()
{
ref=$(git rev-parse --abbrev-ref HEAD 2> /dev/null) \
|| return
echo $ref
}
# If $2 is empty, prepare the commit message.
# See what are the values of $2 there:
# http://git-scm.com/docs/githooks#_prepare_commit_msg
# Useful for leaving the commit message untouched on a merge.
if [ -z "$2" ]
then
BRANCH=$(current_branch)
TIME=$(date +%s)
TEMPORARY_COMMIT_FILE="/tmp/temporary_commit_file.$TIME"
echo "[$PROJECT_NAME] ($BRANCH)" | cat - "$1" > $TEMPORARY_COMMIT_FILE
mv $TEMPORARY_COMMIT_FILE "$1"
fi