Add Pivotal Tracker ticket ID to git commit based on branch name
Put this in .git/hooks/prepare_commit_msg
and make it executable. Now, when you commit without the -m option, the ticket id will be extracted from your branch name and added to the commit message. Your branch name has to end with pt_TICKET_ID
. Example: comment_streams_pt_4354546
.
#!/usr/bin/env ruby
commit_msg = File.read(ARGV[0])
branch = `git rev-parse --abbrev-ref HEAD`
# Adds the ticket id if the branch is named something like this:
# branch_name_pt_4354363
if branch[/pt_\d+$/]
ticket_id = branch[/\d+$/]
new_commit_msg = "Pivotal Tracker: [##{ticket_id}]\n" + commit_msg
File.write(ARGV[0], new_commit_msg)
end
Written by Roger Braun
Related protips
Have a fresh tip? Share with Coderwall community!
Post
Post a tip
Best
#Git
Authors
Sponsored by #native_company# — Learn More
#native_title#
#native_desc#