1
#!/usr/bin/env ruby -KU
2
3
ENV["PATH"] = "/usr/local/bin/:/opt/local/bin:#{ENV["PATH"]}"
4
ENV["RAILS_ENV"] ||= "production"
5
require File.dirname(__FILE__) + "/../config/environment"
6
require "pp"
7
require "fileutils"
8
9
NOOP = ARGV[0] == "dry-run"
10
11
fails = []
12
Repository.find(:all).each do |repo|
13
  begin
14
    next if File.exist?(repo.full_repository_path)
15
    
16
    if repo.project
17
      path = File.join(repo.project.slug, "#{repo.name}.git")
18
    elsif repo.owner
19
      path = File.join(repo.owner.to_param, "#{repo.name}.git")
20
    else
21
      say "no path for #{repo.inspect}"
22
    end
23
    
24
    full_path = File.join(GitoriousConfig["repository_base_path"], path)
25
    full_target_path = File.join(GitoriousConfig["repository_base_path"], "#{repo.full_hashed_path}.git")
26
    unless File.exist?(full_path)
27
      $stderr.puts "\e[1;31m#{path.inspect} doesn't exist!\e[0m"
28
      next
29
    end
30
    #p "#{path} => #{repo.full_hashed_path}.git"
31
    base_dir = full_target_path.split("/")[0..-2].join("/")
32
    unless File.exist?(base_dir)
33
      FileUtils.mkdir_p(base_dir, :verbose => true, :noop => NOOP)
34
    end
35
    FileUtils.mv full_path, full_target_path, :verbose => true, :noop => NOOP
36
    
37
    # relink hooks    
38
    FileUtils.rm(File.join(full_target_path, "hooks"), :verbose => true, :noop => NOOP)
39
    hooks_src = File.join(GitoriousConfig["repository_base_path"], ".hooks")
40
    hooks_dest = File.join(full_target_path, "hooks")
41
    FileUtils.ln_s(hooks_src, hooks_dest, :verbose => true, :noop => NOOP)
42
  rescue => e
43
    fails << [repo.id, e.class.name, e.message, e.backtrace.join("\n  ")]
44
  end
45
end
46
47
puts "\n\nFailures:"
48
pp fails