Skip to content

Instantly share code, notes, and snippets.

@jhelwig
Created October 12, 2012 03:21
Show Gist options
  • Save jhelwig/3877118 to your computer and use it in GitHub Desktop.
Save jhelwig/3877118 to your computer and use it in GitHub Desktop.
guard 'shell' do
watch(/(.*)/) do |m|
if system("git ls-files --exclude-standard -d -o -m | egrep '.' > /dev/null")
test_output = Tempfile.new('guard_commit_test_output')
test_output.close
tests_passing = system("rake 2>&1 >> #{test_output.path}")
commit_message = Tempfile.new('guard_commit_message')
commit_message.write("WIP: #{m[0]} (Tests: #{tests_passing ? 'passing' : 'failing'})\n\n")
commit_message.write(File.read test_output.path)
commit_message.close
system('git add -A')
system("git commit -F #{commit_message.path}")
test_output.unlink
commit_message.unlink
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment