Commit 804168e1 authored by Dmitriy Zaporozhets's avatar Dmitriy Zaporozhets

Merge branch 'use-rugged-for-merge' into 'master'

Merge branches inside one repository using rugged instead of satellites
Signed-off-by: default avatarDmitriy Zaporozhets <dmitriy.zaporozhets@gmail.com>

cc @rspeicher @DouweM

See merge request !918
parents 8969a823 d24c40ec
...@@ -205,7 +205,20 @@ class MergeRequest < ActiveRecord::Base ...@@ -205,7 +205,20 @@ class MergeRequest < ActiveRecord::Base
end end
def check_if_can_be_merged def check_if_can_be_merged
if Gitlab::Satellite::MergeAction.new(self.author, self).can_be_merged? can_be_merged =
if for_fork?
Gitlab::Satellite::MergeAction.new(self.author, self).can_be_merged?
else
rugged = project.repository.rugged
our_commit = rugged.branches[target_branch].target
their_commit = rugged.branches[source_branch].target
if our_commit && their_commit
!rugged.merge_commits(our_commit, their_commit).conflicts?
end
end
if can_be_merged
mark_as_mergeable mark_as_mergeable
else else
mark_as_unmergeable mark_as_unmergeable
......
...@@ -414,8 +414,6 @@ class Repository ...@@ -414,8 +414,6 @@ class Repository
Gitlab::Git::Blob.remove(raw_repository, options) Gitlab::Git::Blob.remove(raw_repository, options)
end end
private
def user_to_comitter(user) def user_to_comitter(user)
{ {
email: user.email, email: user.email,
...@@ -424,6 +422,8 @@ class Repository ...@@ -424,6 +422,8 @@ class Repository
} }
end end
private
def cache def cache
@cache ||= RepositoryCache.new(path_with_namespace) @cache ||= RepositoryCache.new(path_with_namespace)
end end
......
...@@ -5,17 +5,20 @@ module MergeRequests ...@@ -5,17 +5,20 @@ module MergeRequests
# mark merge request as merged and execute all hooks and notifications # mark merge request as merged and execute all hooks and notifications
# Called when you do merge via GitLab UI # Called when you do merge via GitLab UI
class AutoMergeService < BaseMergeService class AutoMergeService < BaseMergeService
attr_reader :merge_request, :commit_message
def execute(merge_request, commit_message) def execute(merge_request, commit_message)
@commit_message = commit_message
@merge_request = merge_request
merge_request.lock_mr merge_request.lock_mr
if Gitlab::Satellite::MergeAction.new(current_user, merge_request).merge!(commit_message) if merge!
merge_request.merge merge_request.merge
create_merge_event(merge_request, current_user) create_merge_event(merge_request, current_user)
create_note(merge_request) create_note(merge_request)
notification_service.merge_mr(merge_request, current_user) notification_service.merge_mr(merge_request, current_user)
execute_hooks(merge_request, 'merge') execute_hooks(merge_request, 'merge')
true true
else else
merge_request.unlock_mr merge_request.unlock_mr
...@@ -26,5 +29,39 @@ module MergeRequests ...@@ -26,5 +29,39 @@ module MergeRequests
merge_request.mark_as_unmergeable merge_request.mark_as_unmergeable
false false
end end
def merge!
if merge_request.for_fork?
Gitlab::Satellite::MergeAction.new(current_user, merge_request).merge!(commit_message)
else
# Merge local branches using rugged instead of satellites
if sha = commit
after_commit(sha, merge_request.target_branch)
end
end
end
def commit
committer = repository.user_to_comitter(current_user)
options = {
message: commit_message,
author: committer,
committer: committer
}
repository.merge(merge_request.source_branch, merge_request.target_branch, options)
end
def after_commit(sha, branch)
commit = repository.commit(sha)
full_ref = 'refs/heads/' + branch
old_sha = commit.parent_id || Gitlab::Git::BLANK_SHA
GitPushService.new.execute(project, current_user, old_sha, sha, full_ref)
end
def repository
project.repository
end
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