Commit e5f8397fd4360ad21ba2f7e9abedb2707f33033f
1 parent
dcbb875c
Exists in
master
and in
4 other branches
fast automerge: done
Showing
5 changed files
with
52 additions
and
21 deletions
Show diff stats
app/models/project/hooks_trait.rb
@@ -102,8 +102,8 @@ module Project::HooksTrait | @@ -102,8 +102,8 @@ module Project::HooksTrait | ||
102 | # Execute web hooks | 102 | # Execute web hooks |
103 | self.execute_web_hooks(oldrev, newrev, ref, user) | 103 | self.execute_web_hooks(oldrev, newrev, ref, user) |
104 | 104 | ||
105 | - # Create repo satellite | ||
106 | - self.create_repo_satellite unless self.satellite_exists? | 105 | + # Create satellite |
106 | + self.satellite.create unless self.satellite.exists? | ||
107 | end | 107 | end |
108 | end | 108 | end |
109 | end | 109 | end |
app/models/project/repository_trait.rb
@@ -37,21 +37,8 @@ module Project::RepositoryTrait | @@ -37,21 +37,8 @@ module Project::RepositoryTrait | ||
37 | end | 37 | end |
38 | end | 38 | end |
39 | 39 | ||
40 | - def path_to_repo_satellite | ||
41 | - File.join(Rails.root, "tmp", "repo_satellites", self.path) | ||
42 | - end | ||
43 | - | ||
44 | - def satellite_exists? | ||
45 | - File.exist? path_to_repo_satellite | ||
46 | - end | ||
47 | - | ||
48 | - def create_repo_satellite | ||
49 | - `git clone #{url_to_repo} #{path_to_repo_satellite}` | ||
50 | - Dir.chdir(path_to_repo_satellite) do | ||
51 | - primary_branch = Grit::Repo.new(".").heads.first.name #usually it`s master | ||
52 | - `git checkout -b __parking_branch` | ||
53 | - `git branch -D #{primary_branch}` | ||
54 | - end | 40 | + def satellite |
41 | + @satellite ||= Gitlabhq::Satellite.new(self) | ||
55 | end | 42 | end |
56 | 43 | ||
57 | def write_hook(name, content) | 44 | def write_hook(name, content) |
lib/gitlab_merge.rb
@@ -29,10 +29,13 @@ class GitlabMerge | @@ -29,10 +29,13 @@ class GitlabMerge | ||
29 | File.open(File.join(Rails.root, "tmp", "merge_repo", "#{project.path}.lock"), "w+") do |f| | 29 | File.open(File.join(Rails.root, "tmp", "merge_repo", "#{project.path}.lock"), "w+") do |f| |
30 | f.flock(File::LOCK_EX) | 30 | f.flock(File::LOCK_EX) |
31 | 31 | ||
32 | - unless project.satellite_exists? | 32 | + unless project.satellite.exists? |
33 | raise "You should run: rake gitlab_enable_automerge" | 33 | raise "You should run: rake gitlab_enable_automerge" |
34 | end | 34 | end |
35 | - Dir.chdir(project.path_to_repo_satellite) do | 35 | + |
36 | + project.satellite.clear | ||
37 | + | ||
38 | + Dir.chdir(project.satellite.path) do | ||
36 | merge_repo = Grit::Repo.new('.') | 39 | merge_repo = Grit::Repo.new('.') |
37 | merge_repo.git.sh "git fetch origin" | 40 | merge_repo.git.sh "git fetch origin" |
38 | merge_repo.git.sh "git config user.name \"#{user.name}\"" | 41 | merge_repo.git.sh "git config user.name \"#{user.name}\"" |
@@ -0,0 +1,41 @@ | @@ -0,0 +1,41 @@ | ||
1 | +module Gitlabhq | ||
2 | + class Satellite | ||
3 | + | ||
4 | + PARKING_BRANCH = "__parking_branch" | ||
5 | + | ||
6 | + attr_accessor :project | ||
7 | + | ||
8 | + def initialize project | ||
9 | + self.project = project | ||
10 | + end | ||
11 | + | ||
12 | + def create | ||
13 | + `git clone #{project.url_to_repo} #{path}` | ||
14 | + end | ||
15 | + | ||
16 | + def path | ||
17 | + File.join(Rails.root, "tmp", "repo_satellites", project.path) | ||
18 | + end | ||
19 | + | ||
20 | + def exists? | ||
21 | + File.exists? path | ||
22 | + end | ||
23 | + | ||
24 | + #will be deleted all branches except PARKING_BRANCH | ||
25 | + def clear | ||
26 | + Dir.chdir(path) do | ||
27 | + heads = Grit::Repo.new(".").heads.map{|head| head.name} | ||
28 | + if heads.include? PARKING_BRANCH | ||
29 | + `git checkout #{PARKING_BRANCH}` | ||
30 | + else | ||
31 | + `git checkout -b #{PARKING_BRANCH}` | ||
32 | + end | ||
33 | + heads.delete(PARKING_BRANCH) | ||
34 | + heads.each do |head| | ||
35 | + `git branch -D #{head}` | ||
36 | + end | ||
37 | + end | ||
38 | + end | ||
39 | + | ||
40 | + end | ||
41 | +end |
lib/tasks/gitlab/enable_automerge.rake
@@ -7,9 +7,9 @@ namespace :gitlab do | @@ -7,9 +7,9 @@ namespace :gitlab do | ||
7 | end | 7 | end |
8 | 8 | ||
9 | Project.find_each do |project| | 9 | Project.find_each do |project| |
10 | - if project.repo_exists? && !project.satellite_exists? | 10 | + if project.repo_exists? && !project.satellite.exists? |
11 | puts "Creating satellite for #{project.name}...".green | 11 | puts "Creating satellite for #{project.name}...".green |
12 | - project.create_repo_satellite | 12 | + project.satellite.create |
13 | end | 13 | end |
14 | end | 14 | end |
15 | 15 |