I use git and like to have a ticket for every bit of work I do on my projects. I also have a preferred way to prefix commit messages, something like:
123 - Fix this broken thing Description of commits here |
Where Fix the broken thing is the ticket subject in RedMine.
It’s not sophisticated or complex but it shows a nice one-liner in GitHub which I like.
To make sure I always stay consistent I have a simple git hook to tweak the commit message:
#!/usr/bin/env ruby require 'rubygems' require 'httparty' REDMINEURL="http://your.redmine" msg = File.read(ARGV[0]) # If the msg starts with number we've been here already # and no doubt someone is amending existing log entries exit if msg =~/^\d/ begin if msg =~ /On branch (\d+)(.+?)\n/ branch = $1 ticketurl = "#{REDMINEURL}/issues/#{branch}.json" puts "Fetching #{ticketurl}" headers = {"User-Agent" => "meh"} ticket = HTTParty.get(ticketurl, {:headers => headers}) msg = "%d - %s\n\n%s" % [ branch, ticket["issue"]["subject"], msg ] File.open(ARGV[0], "w") {|f| f.print msg} end rescue Exception => e puts "git hook failed: #{e.class}: #{e}" sleep 2 exit end |
It requires that I name my branches something like <ticket number>_anything_else which might be too limited but works for me.
This will prepare my commit message with the ticket subject before I commit. I don’t do much off-line coding so generally don’t have to worry about connectivity checks.