Thursday, December 21, 2006

Ruby: rake commit

update: Paul Gross created a GitHub project where these tasks live and can be improved. Check it out at

I wrote in the past about rake pc, the task that I run before checking in. The rake pc task is good, but it stops one step short: actually checking in.

The first implementation of this task used a task with parameters; however, the final implementation uses STDIN.gets and a data file.

The rake commit task also allows you specify a pair if you are working on multiple pairing stations.

desc "Run to check in"
task :commit => :pc do
commit_pair = retrieve_saved_data "pair"
commit_message = retrieve_saved_data "message"
command = %[svn ci -m "#{commit_pair.chomp} - #{commit_message.chomp}"]
puts command
puts %x[#{command}]

def retrieve_saved_data attribute
data_path = File.expand_path(File.dirname(__FILE__) + "/#{attribute}.data")
`touch #{data_path}` unless File.exist? data_path
saved_data =

puts "last #{attribute}: " + saved_data unless saved_data.chomp.empty?
print "#{attribute}: "

input = STDIN.gets
while (saved_data.chomp.empty? && (input.chomp.empty?))
print "#{attribute}: "
input = STDIN.gets
if input.chomp.any?, "w") { |file| file << input }
puts "using: " + saved_data.chomp
input.chomp.any? ? input : saved_data

No comments:

Post a Comment

Note: Only a member of this blog may post a comment.