diff options
author | Dmitriy Zaporozhets <dmitriy.zaporozhets@gmail.com> | 2012-04-22 17:38:39 +0400 |
---|---|---|
committer | Dmitriy Zaporozhets <dmitriy.zaporozhets@gmail.com> | 2012-04-22 17:38:39 +0400 |
commit | 511d07c47c9bf3a18bfa276d452c899369432a22 (patch) | |
tree | aac2e2aa038db98ee8f85c40f95c5a1dd8e78f8e /lib/gitlab_merge.rb | |
parent | 71819dc344a032eb4a7d001c25d096fa959180e6 (diff) | |
parent | e5f8397fd4360ad21ba2f7e9abedb2707f33033f (diff) |
Merge pull request #713 from gitlabhq/fast_automerge
Fast automerge
Diffstat (limited to 'lib/gitlab_merge.rb')
-rw-r--r-- | lib/gitlab_merge.rb | 23 |
1 files changed, 12 insertions, 11 deletions
diff --git a/lib/gitlab_merge.rb b/lib/gitlab_merge.rb index 8e276e0d8a4..98772bf0a24 100644 --- a/lib/gitlab_merge.rb +++ b/lib/gitlab_merge.rb @@ -1,23 +1,20 @@ class GitlabMerge - attr_accessor :project, :merge_path, :merge_request, :user + attr_accessor :project, :merge_request, :user def initialize(merge_request, user) self.user = user self.merge_request = merge_request self.project = merge_request.project - self.merge_path = File.join(Rails.root, "tmp", "merge_repo", project.path, merge_request.id.to_s) - FileUtils.rm_rf(merge_path) - FileUtils.mkdir_p merge_path end def can_be_merged? - pull do |repo, output| + process do |repo, output| !(output =~ /Automatic merge failed/) end end def merge - pull do |repo, output| + process do |repo, output| if output =~ /Automatic merge failed/ false else @@ -27,19 +24,23 @@ class GitlabMerge end end - def pull + def process Grit::Git.with_timeout(30.seconds) do File.open(File.join(Rails.root, "tmp", "merge_repo", "#{project.path}.lock"), "w+") do |f| f.flock(File::LOCK_EX) - self.project.repo.git.clone({:branch => merge_request.target_branch}, project.url_to_repo, merge_path) - unless File.exist?(self.merge_path) - raise "Gitlab user do not have access to repo. You should run: rake gitlab_enable_automerge" + unless project.satellite.exists? + raise "You should run: rake gitlab_enable_automerge" end - Dir.chdir(merge_path) 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}\"" merge_repo.git.sh "git config user.email \"#{user.email}\"" + merge_repo.git.sh "git checkout -b #{merge_request.target_branch} origin/#{merge_request.target_branch}" output = merge_repo.git.pull({}, "--no-ff", "origin", merge_request.source_branch) yield(merge_repo, output) end |