Skip to content

Commit 59ba5e2

Browse files
committed
Add djdefi's version
1 parent e865a97 commit 59ba5e2

File tree

1 file changed

+16
-26
lines changed

1 file changed

+16
-26
lines changed
Lines changed: 16 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,19 @@
1-
#!/usr/bin/env bash
1+
#!/bin/bash
2+
#
3+
# check commit messages for JIRA issue numbers formatted as [JIRA-<issue number>]
24

3-
zero_commit="0000000000000000000000000000000000000000"
5+
REGEX="\[JIRA\-[0-9]*\]"
46

5-
read oldrev newrev refname
6-
echo $oldrev $newrev $refname
7+
ERROR_MSG="[POLICY] The commit doesn't reference a JIRA issue"
78

8-
check_message_format ()
9-
# enforced custom commit message format
10-
{
11-
message=`git cat-file commit $newrev | sed '1,/^$/d'`
12-
regex="/*\[jira-.*\]"
13-
echo "[COMMIT MESSAGE]:" $message
14-
if [[ $message =~ $regex ]];
15-
then
16-
echo "Commit message looks good!"
17-
exit 0
18-
else
19-
echo "[POLICY] Commit message does not contain a JIRA ticket #"
20-
exit 1
21-
22-
fi
23-
}
24-
25-
if [ "$newrev" = "$zero_commit" ]; then
26-
continue
27-
else
28-
check_message_format
29-
fi
9+
while read OLDREV NEWREV REFNAME ; do
10+
for COMMIT in `git rev-list $OLDREV..$NEWREV`;
11+
do
12+
MESSAGE=`git cat-file commit $COMMIT | sed '1,/^$/d'`
13+
if ! echo $MESSAGE | grep -iqE "$REGEX"; then
14+
echo "$ERROR_MSG: $MESSAGE" >&2
15+
exit 1
16+
fi
17+
done
18+
done
19+
exit 0

0 commit comments

Comments
 (0)