Hooky lets you write Git repository hooks with Rake. If you already have a Rakefile, write your hooks in Ruby! Hooky provides tasks for most Git hooks, and lets you easily add behavior.
Git hooks are powerful: Check the Git documentation (linked above) for detailed descriptions and lifecycle order.
# in your Rakefile require "hooky/tasks" task "git:applypatch-msg", [:file] do |_, args| puts "Proposed git-am commit msg: #{IO.read(args[:file])}" end task "git:commit-msg", [:file] do |_, args| puts "Proposed commit msg: #{IO.read(args[:file])}" end task "git:post-applypatch" do puts "Patch applied by git-am!" end task "git:post-checkout", [:old, :new, :branch] do |_, args| puts "you just switched branches!" if args[:branch] puts "old SHA: #{args[:old]}, new SHA: #{args[:new]}" end task "git:post-commit" puts "You made a commit!" end task "git:post-merge", [:squash] do |_, args| puts "You just did a merge!" puts "It was a squash." if args[:squash] end task "git:pre-applypatch" do puts "git-am is about to commit a patch!" end task "git:pre-auto-gc" do puts "git gc --auto is about to run!" end task "git:pre-commit" do puts "You're about to commit!" end task "git:pre-rebase" do puts "You're about to rebase!" end task "git:prepare-commit-msg", [:file, :source, :sha] do |_, args| puts "Building a commit message!" end
$ gem install hooky # in your project $ rake hooky:install
hooky:install
symlinks all hooks to .git/hooks/hooky
, a stub that delegates to your Rakefile, but it won’t overwrite any hooks you’ve already created.
Copyright 2009 John Barnette (jbarnette@rubyforge.org)
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the ‘Software’), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED ‘AS IS’, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.