Redirect to proper messages tab after bulk update
[gitorious.git] / script / shard_git_repositories_by_hash
blob1402c9b6495b2c4c7ce86ae38ab18e6a69610d81
1 #!/usr/bin/env ruby -KU
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"
9 NOOP = ARGV[0] == "dry-run"
11 fails = []
12 Repository.all.each do |repo|
13 begin
14 next if File.exist?(repo.full_repository_path)
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
24 full_path = File.join(RepositoryRoot.default_base_path, path)
25 full_target_path = File.join(RepositoryRoot.default_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
37 # relink hooks
38 FileUtils.rm(File.join(full_target_path, "hooks"), :verbose => true, :noop => NOOP)
39 hooks_src = File.join(RepositoryRoot.default_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
47 puts "\n\nFailures:"
48 pp fails