fast automerge: done
This commit is contained in:
parent
dcbb875c46
commit
e5f8397fd4
|
@ -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
|
||||||
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
|
||||||
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}\""
|
||||||
|
|
41
lib/gitlabhq/satellite.rb
Normal file
41
lib/gitlabhq/satellite.rb
Normal 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
|
|
@ -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
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue