class Gitlab::Merge

Attributes

merge_request[RW]
project[RW]
user[RW]

Public Class Methods

new(merge_request, user) click to toggle source
# File lib/gitlab/merge.rb, line 5
def initialize(merge_request, user)
  @merge_request = merge_request
  @project = merge_request.project
  @user = user
end

Public Instance Methods

can_be_merged?() click to toggle source
# File lib/gitlab/merge.rb, line 11
def can_be_merged?
  in_locked_and_timed_satellite do |merge_repo|
    merge_in_satellite!(merge_repo)
  end
end
merge!() click to toggle source

Merges the source branch into the target branch in the satellite and pushes it back to Gitolite. It also removes the source branch if requested in the merge request.

Returns false if the merge produced conflicts Returns false if pushing from the satallite to Gitolite failed or was rejected Returns true otherwise

# File lib/gitlab/merge.rb, line 24
def merge!
  in_locked_and_timed_satellite do |merge_repo|
    if merge_in_satellite!(merge_repo)
      # push merge back to Gitolite
      # will raise CommandFailed when push fails
      merge_repo.git.push({raise: true}, :origin, merge_request.target_branch)

      # remove source branch
      if merge_request.should_remove_source_branch && !project.root_ref?(merge_request.source_branch)
        # will raise CommandFailed when push fails
        merge_repo.git.push({raise: true}, :origin, ":#{merge_request.source_branch}")
      end

      # merge, push and branch removal successful
      true
    end
  end
rescue Grit::Git::CommandFailed
  false
end