| c699d6f by David A. Cuadrado at 2008-03-20 |
1 |
#!/usr/bin/env ruby |
|
2 |
|
|
3 |
require 'tmpdir' |
|
4 |
require "fileutils" |
|
5 |
|
|
6 |
LOCK_FILE_PATH = File.join(Dir.tmpdir, "gitorious_task_lockfile") |
|
7 |
ENV["PATH"] = "/usr/local/bin/:/opt/local/bin:#{ENV["PATH"]}" |
|
8 |
|
|
9 |
if File.exist?(LOCK_FILE_PATH) |
|
10 |
$stderr.puts "Task lockfile '#{LOCK_FILE_PATH}' exists!" |
|
11 |
exit(1) |
|
12 |
end |
|
13 |
|
|
14 |
ENV["RAILS_ENV"] ||= "production" |
|
15 |
require File.dirname(__FILE__) + "/../config/environment" |
|
16 |
|
|
17 |
|
|
18 |
repo_path = GitoriousConfig['repository_base_path'] |
|
19 |
repo_hooks = File.join(repo_path, ".hooks") |
|
20 |
gitorious_hooks = File.expand_path(File.join(File.dirname(__FILE__), "../data/hooks")) |
|
21 |
|
|
22 |
if not File.symlink?(repo_hooks) |
|
23 |
if File.exist?(repo_hooks) |
|
24 |
FileUtils.mv(repo_hooks, File.join(repo_path, ".hooks.backup")) |
|
25 |
end |
|
26 |
|
|
27 |
FileUtils.ln_s(gitorious_hooks, repo_hooks) |
|
28 |
elsif File.readlink(repo_hooks) != gitorious_hooks |
|
29 |
# puts "ln -sf #{gitorious_hooks} #{repo_hooks}" |
|
30 |
File.unlink(repo_hooks) |
|
31 |
FileUtils.ln_sf(gitorious_hooks, repo_hooks) |
|
32 |
end |
|
33 |
|
|
34 |
Dir.glob("#{repo_path}/**/*.git").each do |repo| |
|
35 |
Dir.chdir(repo) do |
|
36 |
hooks = File.join(repo, "hooks") |
|
37 |
unless File.symlink?(hooks) |
|
38 |
print "=> Fixing #{hooks}... " |
|
39 |
$stdout.flush |
|
40 |
|
|
41 |
if File.exist?(hooks) |
|
42 |
FileUtils.mv(hooks, "hooks.backup") |
|
43 |
end |
|
44 |
|
|
45 |
FileUtils.ln_s("../../.hooks", "hooks") |
|
46 |
|
|
47 |
puts "[OK]" |
|
48 |
end |
|
49 |
end |
|
50 |
end |