Created
August 27, 2009 22:00
-
-
Save rdamen/176599 to your computer and use it in GitHub Desktop.
git hook symlink fun
This file contains 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 | |
# 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