diff options
author | David A. Cuadrado <krawek@gmail.com> | 2008-03-13 12:33:36 -0500 |
---|---|---|
committer | David A. Cuadrado <krawek@gmail.com> | 2008-03-20 16:36:06 -0500 |
commit | c699d6f0afde34d3ed41bd9d99f67e9b6de9267b (patch) | |
tree | bb8dd8bee52b7ccc42d8e0d2b043bbb04751fefb /script/fixup_hooks | |
parent | 31a96379c9642b75f3b32fd4b20d6a602c90a63f (diff) | |
download | gitorious-mainline-outdated-c699d6f0afde34d3ed41bd9d99f67e9b6de9267b.zip gitorious-mainline-outdated-c699d6f0afde34d3ed41bd9d99f67e9b6de9267b.tar.gz gitorious-mainline-outdated-c699d6f0afde34d3ed41bd9d99f67e9b6de9267b.tar.bz2 |
Script to setup the hooks
Check and fix symlinks
Diffstat (limited to 'script/fixup_hooks')
-rwxr-xr-x | script/fixup_hooks | 50 |
1 files changed, 50 insertions, 0 deletions
diff --git a/script/fixup_hooks b/script/fixup_hooks new file mode 100755 index 0000000..ad8ef59 --- /dev/null +++ b/script/fixup_hooks @@ -0,0 +1,50 @@ +#!/usr/bin/env ruby + +require 'tmpdir' +require "fileutils" + +LOCK_FILE_PATH = File.join(Dir.tmpdir, "gitorious_task_lockfile") +ENV["PATH"] = "/usr/local/bin/:/opt/local/bin:#{ENV["PATH"]}" + +if File.exist?(LOCK_FILE_PATH) + $stderr.puts "Task lockfile '#{LOCK_FILE_PATH}' exists!" + exit(1) +end + +ENV["RAILS_ENV"] ||= "production" +require File.dirname(__FILE__) + "/../config/environment" + + +repo_path = GitoriousConfig['repository_base_path'] +repo_hooks = File.join(repo_path, ".hooks") +gitorious_hooks = File.expand_path(File.join(File.dirname(__FILE__), "../data/hooks")) + +if not File.symlink?(repo_hooks) + if File.exist?(repo_hooks) + FileUtils.mv(repo_hooks, File.join(repo_path, ".hooks.backup")) + end + + FileUtils.ln_s(gitorious_hooks, repo_hooks) +elsif File.readlink(repo_hooks) != gitorious_hooks +# puts "ln -sf #{gitorious_hooks} #{repo_hooks}" + File.unlink(repo_hooks) + FileUtils.ln_sf(gitorious_hooks, repo_hooks) +end + +Dir.glob("#{repo_path}/**/*.git").each do |repo| + Dir.chdir(repo) do + hooks = File.join(repo, "hooks") + unless File.symlink?(hooks) + print "=> Fixing #{hooks}... " + $stdout.flush + + if File.exist?(hooks) + FileUtils.mv(hooks, "hooks.backup") + end + + FileUtils.ln_s("../../.hooks", "hooks") + + puts "[OK]" + end + end +end |