Last active
August 15, 2016 09:48
-
-
Save RunsFor/6b682635d17d551006edd32248219b56 to your computer and use it in GitHub Desktop.
Git commit hook to extract issue id from the branch name and prefix commit message with it
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/bash | |
| BRANCH_NAME=$(git branch | grep '*' | sed 's/* //') | |
| if [ $BRANCH_NAME != '(no branch)' ] | |
| then | |
| # создаем временный файл | |
| tempname="ticket-id-XXXX"; | |
| tempfile=`mktemp $tempname`; | |
| # выделяем из имени бранча номер тикета. Бранч всегда называется по шаблону Номер_Краткое_Описание | |
| # например 1364_restore_xterm_title или 1364-restore-xterm-title | |
| ticket=`git branch|grep '* '| sed -E 's/(^\w*[^0-9]+|^)([0-9]+)(\-|_).*/\2/'`; | |
| # берем сообщение комита | |
| message=`cat $1`; | |
| # если это первый коммит в бранче то вначале описания к коммиту добавляем [#Номер] | |
| if [[ $ticket =~ ^[0-9]+$ ]]; then | |
| # сливаем во временный файл номер и текст коммита | |
| echo "[#$ticket] $message" >> "$tempfile"; | |
| # переписываем файл коммита временным файлом | |
| mv "$tempfile" "$1" | |
| else | |
| rm $tempfile | |
| fi | |
| fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment