Skip to content

Instantly share code, notes, and snippets.

@sletix
Last active July 1, 2016 13:37
Show Gist options
  • Save sletix/2865161 to your computer and use it in GitHub Desktop.
Save sletix/2865161 to your computer and use it in GitHub Desktop.
Git hook for put pivotal-ticket-id in commit msg
#!/bin/bash
tempfile=`mktemp`;
ticket=`git branch|grep '* '|cut -f 2 -d '-'`;
message=`cat $1`;
if [[ $ticket =~ ^[0-9]{7,}$ ]]; then
echo -e "$message\n\n--\nPivotalTracker: [#$ticket] https://www.pivotaltracker.com/story/show/$ticket" >> "$tempfile";
mv "$tempfile" "$1"
else
rm $tempfile
fi
@sletix
Copy link
Author

sletix commented Apr 7, 2016

Auto-adding ticket id from branch name to commit message

how to install:

  $ cd path/to/project/.git/hooks
  $ wget https://gist.githubusercontent.com/sletix/2865161/raw/8caeeb2c18744430ae31409fb704cca68ab871a7/commit-msg
  $ chmod +x commit-msg

use case:

when your start to develop some feature from pivotal tracker, you should create branch with ticket ID

  $ git checkout -b SCOR-116957925 origin/develop
  # ... write something commit ...

  $ git commit -m 'Some message'
  [SCORE-116957925 4f2ef417] Some message
   3 files changed, ... insertions(+), ... deletions(-)

  $ git log --name-status HEAD^..HEAD
  commit 4f2ef41703d6b5c846ce02c71e94b2cf98ba3b6b
  Author: Oleg V Artamonov <oleg@artamonov.ru>
  Date:   Thu Apr 7 20:59:07 2016 +0300

      Some message

      --
      PivotalTracker: [#116957925] https://www.pivotaltracker.com/story/show/116957925

  M       app/views/shared/stats/_ga.html.erb
  M       app/views/shared/stats/_gmt.html.erb
  M       config/settings.yml

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