fast automerge: done

This commit is contained in:
Valery Sizov 2012-04-22 16:14:01 +03:00
parent dcbb875c46
commit e5f8397fd4
5 changed files with 52 additions and 21 deletions

View file

@ -102,8 +102,8 @@ module Project::HooksTrait
# Execute web hooks
self.execute_web_hooks(oldrev, newrev, ref, user)
# Create repo satellite
self.create_repo_satellite unless self.satellite_exists?
# Create satellite
self.satellite.create unless self.satellite.exists?
end
end
end

View file

@ -37,21 +37,8 @@ module Project::RepositoryTrait
end
end
def path_to_repo_satellite
File.join(Rails.root, "tmp", "repo_satellites", self.path)
end
def satellite_exists?
File.exist? path_to_repo_satellite
end
def create_repo_satellite
`git clone #{url_to_repo} #{path_to_repo_satellite}`
Dir.chdir(path_to_repo_satellite) do
primary_branch = Grit::Repo.new(".").heads.first.name #usually it`s master
`git checkout -b __parking_branch`
`git branch -D #{primary_branch}`
end
def satellite
@satellite ||= Gitlabhq::Satellite.new(self)
end
def write_hook(name, content)

View file

@ -29,10 +29,13 @@ class GitlabMerge
File.open(File.join(Rails.root, "tmp", "merge_repo", "#{project.path}.lock"), "w+") do |f|
f.flock(File::LOCK_EX)
unless project.satellite_exists?
unless project.satellite.exists?
raise "You should run: rake gitlab_enable_automerge"
end
Dir.chdir(project.path_to_repo_satellite) do
project.satellite.clear
Dir.chdir(project.satellite.path) do
merge_repo = Grit::Repo.new('.')
merge_repo.git.sh "git fetch origin"
merge_repo.git.sh "git config user.name \"#{user.name}\""

41
lib/gitlabhq/satellite.rb Normal file
View file

@ -0,0 +1,41 @@
module Gitlabhq
class Satellite
PARKING_BRANCH = "__parking_branch"
attr_accessor :project
def initialize project
self.project = project
end
def create
`git clone #{project.url_to_repo} #{path}`
end
def path
File.join(Rails.root, "tmp", "repo_satellites", project.path)
end
def exists?
File.exists? path
end
#will be deleted all branches except PARKING_BRANCH
def clear
Dir.chdir(path) do
heads = Grit::Repo.new(".").heads.map{|head| head.name}
if heads.include? PARKING_BRANCH
`git checkout #{PARKING_BRANCH}`
else
`git checkout -b #{PARKING_BRANCH}`
end
heads.delete(PARKING_BRANCH)
heads.each do |head|
`git branch -D #{head}`
end
end
end
end
end

View file

@ -7,9 +7,9 @@ namespace :gitlab do
end
Project.find_each do |project|
if project.repo_exists? && !project.satellite_exists?
if project.repo_exists? && !project.satellite.exists?
puts "Creating satellite for #{project.name}...".green
project.create_repo_satellite
project.satellite.create
end
end