forked from Djuuu/git-mr
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathprepare-commit-msg
More file actions
executable file
·23 lines (17 loc) · 856 Bytes
/
Copy pathprepare-commit-msg
File metadata and controls
executable file
·23 lines (17 loc) · 856 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
#!/usr/bin/env sh
################################################################################
# When on a branch referring to a Jira issue,
# ensure commit messages start with the issue reference
default_pattern="[A-Z]{2}-[0-9]+"
jira_code_pattern="${JIRA_CODE_PATTERN:-$default_pattern}"
current_branch=$(git rev-parse --abbrev-ref HEAD)
issue_code=$(echo "${current_branch}" | grep -Eo "$jira_code_pattern" | tail -n1)
[ -n "$issue_code" ] || exit 0 # No issue code detected
current_msg=$(cat "$1")
msg_code=$(echo "${current_msg}" | grep -iEo "$jira_code_pattern" | tail -n1)
[ -z "$msg_code" ] || exit 0 # existing issue code in message
if case "$current_msg" in "fixup! "*) ;; *) false;; esac; then
exit 0 # don't alter fixup messages
fi
echo "Prefixing message with issue code: $issue_code" >&2
sed -i.bak -e "1s/^/$issue_code /" "$1"