27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
|
# File 'lib/gitpusher/runner.rb', line 27
def self.mirror(src_repo)
repo_name = File.basename(src_repo.url).gsub(/.git$/, '')
repo_path = File.join(base_dir, "#{repo_name}.git")
unless File.exist?(repo_path)
puts "[#{Process.pid}][#{repo_name}]Cloning #{src_repo.url} ..."
`git clone --mirror #{src_repo.url}`
end
local_repo = Grit::Repo.new(repo_path)
has_remote_mirror = false
local_repo.remote_list.each do |remote|
has_remote_mirror = true if remote === 'mirror'
end
mirror_repo = dest.repo(repo_name) || dest.create_repo(repo_name)
unless has_remote_mirror
local_repo.git.remote({}, 'add', 'mirror', mirror_repo.url)
end
Dir.chdir(repo_path) do
puts "[#{Process.pid}][#{repo_name}]Pruning all stale branches of #{repo_name} ..."
local_repo.git.remote({}, 'prune', 'origin')
puts "[#{Process.pid}][#{repo_name}]Fetching from #{src_repo.url} ..."
local_repo.git.fetch({ :timeout => 300 }, 'origin')
puts "[#{Process.pid}][#{repo_name}]Pushing to #{mirror_repo.url} ..."
local_repo.git.push({ :timeout => 300 }, 'mirror','--mirror')
end
end
|