-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathprepare-commit-msg
More file actions
executable file
·51 lines (46 loc) · 1.68 KB
/
prepare-commit-msg
File metadata and controls
executable file
·51 lines (46 loc) · 1.68 KB
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
#!/bin/bash
if [ -z "$2" ]
then
echo > "$1"
# Ticket number as first commit entry
if [ -f /tmp/.git-rejected-commit-msg ]
then
cat /tmp/.git-rejected-commit-msg | grep -v '^$' | grep -v '^*' > "$1"
echo -e "\n" >> "$1"
else
TICKET=$(git symbolic-ref HEAD | sed 's/[^0-9]*//')
if [ -n "$TICKET" ]
then
echo "#$TICKET " > "$1"
echo -e "\n" >> "$1"
else
TICKET=$(git last --author="$(git config user.name)" --oneline | sed 's/.*\#\([0-9]*\).*/\1/')
if [ -n "$TICKET" ] && [ "$(git last --author=$(git config user.name | sed 's/^\(.*\) .*$/\1/') --oneline)" != "$TICKET" ]
then
echo "#$TICKET " > "$1"
echo -e "\n" >> "$1"
echo "* Previous commits by me:" >> "$1"
git log --author="$(git config user.name)" --oneline -n 3 | sed 's/^/* /' >> "$1"
echo -e "\n" >> "$1"
else
echo -e "\n" >> "$1"
fi
fi
fi
if [ "$(git config hooks.ticketnumbercheck)" == "on" ]
then
python -c "print '*' * 80" >> "$1"
echo -e "* Commit without ticket number will be rejected!" >> "$1"
python -c "print '*' * 80" >> "$1"
echo -e "\n" >> "$1"
fi
python -c "print '*' * 80" >> "$1"
echo "* You are on $(git branch | grep '^\*' | awk '{print $2}') branch." >> "$1"
python -c "print '*' * 80" >> "$1"
echo -e "\n" >> "$1"
python -c "print '*' * 80" >> "$1"
echo -e "* Changed files:" >> "$1"
git status --porcelain | sed 's/^/* /' >> "$1"
python -c "print '*' * 80" >> "$1"
echo -e "\n" >> "$1"
fi