Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # abort if .git-hooks is not present
- # add .git-hooks to .git-ignore so people can opt-in
- if [ ! -f .git-hooks ]; then
- exit 0
- fi
- # some commit operations we dont want to prefix the message
- if [[ "$2" == "merge" || "$2" == "commit" || "$2" == "template" || "$2" == "squash" ]]; then
- echo "Not a regular commit so ignoring.."
- exit 0
- fi
- # get initials from the dev's GIT config
- # got to be a tidier regex for this
- initials=$(git var GIT_AUTHOR_IDENT | sed 's/^\([A-Za-z]\{1\}\).* \([A-Za-z]\{1\}\).*$/\1\2/')
- ##
- # override the prefix
- ##
- # 1. default is just the dev's initials
- prefix="[$initials][]"
- # 2. dev is continuing a line of commits on the same ticket (i.e not after a merge or after someone elses line of commits)
- # [RS DW][MR-312] updated... -> extract [RS DW][MR-312]
- # [DW JR][MR-310] send.... -> ignore
- # Merged branch... -> ignore
- regex="^\[${initials}"
- match=$(git log -1 --pretty=%B | grep -e "$regex")
- if [ -n "$match" ]; then
- prefix=$(git log -1 --pretty=%B | sed 's/^\(\[.*\]\).*$/\1/')
- fi
- # add prefix
- echo "$prefix\n$(cat $1)" > "$1"
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement