Skip to content

Instantly share code, notes, and snippets.

@rdamen
Created August 27, 2009 22:00
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save rdamen/176599 to your computer and use it in GitHub Desktop.
Save rdamen/176599 to your computer and use it in GitHub Desktop.
git hook symlink fun
#!/usr/bin/env ruby
# symlink git hooks
require 'pathname'
@hooks_dir = ARGV.first || 'hooks'
def path(yo)
Pathname.new(File.expand_path(yo))
end
def hooks
path("#{@hooks_dir}").children
end
def find(try = path('.'))
return nil if try == try.parent
if try.children.include? path("#{try}/.git")
path(try)
else
find(try.parent)
end
end
def root
@root ||= find
end
def hookup
dst = path("#{root}/.git/hooks")
hooks.each do |hook|
link(hook.relative_path_from(dst), dst)
end
end
def link src, dst
cmd = "ln -s #{src} #{dst}"
puts(cmd)
system(cmd)
end
hookup
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment