Created
April 23, 2014 19:00
-
-
Save sbrauer/11228276 to your computer and use it in GitHub Desktop.
gitcommit
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
#!/usr/bin/env ruby | |
# A wrapper around "git commit" that provides a template message | |
# conforming to RentPath conventions. | |
# by Sam Brauer 2013-09-05 | |
# inspired by Zander Hill's vim macro (https://gist.github.com/anonymous/b6cf9e57c9bb26cf3f3f) | |
# Assumes branches are named with the following components separated | |
# by underscores: | |
# 1. developer initials (one or more of these components are allowed) | |
# 2. story number | |
# 3. free text description (optional; may contain underscores) | |
# Examples: | |
# "sb_12345_fix_serious_bug" | |
# "sb_zh_67890" (two devs, no optional description) | |
require 'tempfile' | |
branch_name = `git rev-parse --abbrev-ref HEAD`.chomp | |
abort if branch_name == '' | |
initials = 'XX' | |
number = '00000' | |
components = branch_name.split('_') | |
number_idx = components.find_index { |x| x.match /\d/ } | |
if number_idx | |
number = components[number_idx] | |
initials = components[0...number_idx].join('/').upcase | |
end | |
template_string = "[#{initials}][#{number}] " | |
file = Tempfile.new('commit-template') | |
file.write(template_string) | |
file.close | |
begin | |
cmd = "git commit --template=#{file.path} #{ARGV.join(' ')}" | |
system(cmd) | |
ensure | |
file.unlink | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment