Skip to content

Instantly share code, notes, and snippets.

@whalemare
Last active July 15, 2019 09:49
Show Gist options
  • Save whalemare/a838e991b5c5203242cb6c75ec535f73 to your computer and use it in GitHub Desktop.
Save whalemare/a838e991b5c5203242cb6c75ec535f73 to your computer and use it in GitHub Desktop.
Add link to redmine ticket by working branch name
message=$(cat "$1")
currentBranch=$(git rev-parse --abbrev-ref HEAD)
currentBranch=$(echo "$currentBranch" | grep -o '[a-zA-Zа-яА-Я]\+-\d*')
echo "current ticket = $currentBranch"
countTrackerWords=$(echo "$message" | grep -w -c Tracker)
if [ $countTrackerWords == 0 ] && [ ! -z $currentBranch ]
then {
echo ""
echo "Redmine:"
echo "refs $currentBranch"
} >> "$1"
fi
message=$(cat "$1")
currentBranch=$(git rev-parse --abbrev-ref HEAD)
currentBranch=$(echo "$currentBranch" | grep -o '[a-zA-Zа-яА-Я]\+-\d*')
echo "current ticket = $currentBranch"
countTrackerWords=$(echo "$message" | grep -w -c Tracker)
if [ $countTrackerWords == 0 ] && [ ! -z $currentBranch ]
then {
echo ""
echo "Tracker:"
echo "$currentBranch"
} >> "$1"
fi
@whalemare
Copy link
Author

whalemare commented Nov 24, 2017

This is git hook, which adds to the end of message your commits the #id of the redmine task.

How use

  1. Put code from bash script into your/project/path/.git/hooks/commit-msg.sample
  2. Rename commit-msg.sample to commit-msg for enable this git hook

for geeks: not tested, but you need do something like this

cd your/project/path/
cd .git/hooks
open commit-msg.sample
# COPY-PASTE CODE FROM SCRIPT IN THE TOP
# SAVE AND CLOSE
mv commit-msg.sample commit-msg

@whalemare
Copy link
Author

cat commit-msg
echo "CTRL+V text here" > commit-msg

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment