Commit e5f8397f authored by Valery Sizov's avatar Valery Sizov

fast automerge: done

parent dcbb875c
...@@ -102,8 +102,8 @@ module Project::HooksTrait ...@@ -102,8 +102,8 @@ module Project::HooksTrait
# Execute web hooks # Execute web hooks
self.execute_web_hooks(oldrev, newrev, ref, user) self.execute_web_hooks(oldrev, newrev, ref, user)
# Create repo satellite # Create satellite
self.create_repo_satellite unless self.satellite_exists? self.satellite.create unless self.satellite.exists?
end end
end end
end end
...@@ -37,21 +37,8 @@ module Project::RepositoryTrait ...@@ -37,21 +37,8 @@ module Project::RepositoryTrait
end end
end end
def path_to_repo_satellite def satellite
File.join(Rails.root, "tmp", "repo_satellites", self.path) @satellite ||= Gitlabhq::Satellite.new(self)
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
end end
def write_hook(name, content) def write_hook(name, content)
......
...@@ -29,10 +29,13 @@ class GitlabMerge ...@@ -29,10 +29,13 @@ class GitlabMerge
File.open(File.join(Rails.root, "tmp", "merge_repo", "#{project.path}.lock"), "w+") do |f| File.open(File.join(Rails.root, "tmp", "merge_repo", "#{project.path}.lock"), "w+") do |f|
f.flock(File::LOCK_EX) f.flock(File::LOCK_EX)
unless project.satellite_exists? unless project.satellite.exists?
raise "You should run: rake gitlab_enable_automerge" raise "You should run: rake gitlab_enable_automerge"
end 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 = Grit::Repo.new('.')
merge_repo.git.sh "git fetch origin" merge_repo.git.sh "git fetch origin"
merge_repo.git.sh "git config user.name \"#{user.name}\"" merge_repo.git.sh "git config user.name \"#{user.name}\""
......
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
...@@ -7,9 +7,9 @@ namespace :gitlab do ...@@ -7,9 +7,9 @@ namespace :gitlab do
end end
Project.find_each do |project| 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 puts "Creating satellite for #{project.name}...".green
project.create_repo_satellite project.satellite.create
end end
end end
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment