Created
August 24, 2017 16:18
-
-
Save pawcik/1a9c611ed233745c6fd87dd69e55363d to your computer and use it in GitHub Desktop.
Git hook: prepare-commit-msg. Prefix git commit message with ticket id.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/bin/sh | |
| # | |
| # Automatically adds jira id to commit message. | |
| # The branch name must contains valid ticket prefix, eg. AT-[0-9]{1,} | |
| # | |
| # to support multiple projects edit $projects variable | |
| projects="AT IT TEST GIT" | |
| content="$(cat "$1")" | |
| ticket="" | |
| for p in $projects; do | |
| pattern="$p-[0-9]*" | |
| ticket=$(git symbolic-ref --short HEAD | sed 's/.*\('$pattern'\).*/\1/') | |
| if [[ "$jira" =~ $pattern ]]; then | |
| break | |
| else | |
| ticket="" | |
| fi | |
| done | |
| if [[ $ticket == "" ]]; then | |
| echo "${content}" > "$1" | |
| exit 0 | |
| fi | |
| prefix="[${ticket}]" | |
| if [[ $content == "${prefix}"* ]]; then | |
| echo "${content}" > "$1" | |
| else | |
| echo "${prefix} "' '"${content}" > "$1" | |
| fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment