-
Notifications
You must be signed in to change notification settings - Fork 12
/
Copy pathcommit-msg
executable file
·66 lines (58 loc) · 1.48 KB
/
commit-msg
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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
#!/bin/sh
# Sample Pit integration hook.
#
# 1. Appends Pit task number to the commit message when you use
# task number as part of your Git branch name. Specifically,
# leading or trailing digits of the branch name are treated
# as Pit task number.
#
# 2. Lets you specify task status and updates it in Pit accordingly.
#
# 3. Creates task note with the complete commit massage.
#
# Drop into .git/hooks/commit-msg
# chmod +x .git/hooks/commit-msg
pit="/usr/local/bin/pit"
exec < /dev/tty
ref=$(git symbolic-ref HEAD 2> /dev/null) || return
branch=${ref#refs/heads/}
if [[ $branch =~ ^([0-9]+) ]]; then
pit_task=${BASH_REMATCH[1]}
else
if [[ $branch =~ ([0-9]+)$ ]]; then
pit_task=${BASH_REMATCH[1]}
fi
fi
if [ -n "$pit_task" ]; then
pit_task=${BASH_REMATCH[1]}
echo "What is the status of task ${pit_task}?"
echo " (I)n progress"
echo " (P)ostponed"
echo " (O)pen"
echo " (D)one"
echo " (T)emp commit, ignore"
echo "Enter the status for task ${pit_task} [D]: "
read selection
status="done"
case $selection in
'i'|'I' )
status="in progress"
;;
'p'|'P' )
status="postponed"
;;
'o'|'O' )
status="open"
;;
't'|'T' )
# This is a test commit and pit should ignore it
exit 0
;;
esac
commit="`grep -v "^#" $1`"
append="[task ${pit_task}, status:${status}]"
echo >&2 "$append" >> "$1"
"${pit}" task -e "${pit_task}" -s "${status}"
"${pit}" note -c "${commit} ${append}"
exit 0
fi