Commit 88115792 authored by Dmitriy Zaporozhets's avatar Dmitriy Zaporozhets

Implement fast-forward merge

Signed-off-by: default avatarDmitriy Zaporozhets <dmitriy.zaporozhets@gmail.com>
parent 584ff6f8
...@@ -2,7 +2,7 @@ class Projects::MergeRequestsController < Projects::ApplicationController ...@@ -2,7 +2,7 @@ class Projects::MergeRequestsController < Projects::ApplicationController
before_action :module_enabled before_action :module_enabled
before_action :merge_request, only: [ before_action :merge_request, only: [
:edit, :update, :show, :diffs, :commits, :merge, :merge_check, :edit, :update, :show, :diffs, :commits, :merge, :merge_check,
:ci_status, :toggle_subscription, :approve :ci_status, :toggle_subscription, :approve, :ff_merge
] ]
before_action :closes_issues, only: [:edit, :update, :show, :diffs, :commits] before_action :closes_issues, only: [:edit, :update, :show, :diffs, :commits]
before_action :validates_merge_request, only: [:show, :diffs, :commits] before_action :validates_merge_request, only: [:show, :diffs, :commits]
...@@ -218,6 +218,19 @@ class Projects::MergeRequestsController < Projects::ApplicationController ...@@ -218,6 +218,19 @@ class Projects::MergeRequestsController < Projects::ApplicationController
redirect_to merge_request_path(@merge_request) redirect_to merge_request_path(@merge_request)
end end
def ff_merge
return access_denied! unless @merge_request.can_be_merged_by?(current_user)
return render_404 unless @merge_request.approved?
if @merge_request.ff_merge_possible?
MergeRequests::FfMergeService.new(merge_request.target_project, current_user).
execute(merge_request)
@status = true
else
@status = false
end
end
protected protected
def selected_target_project def selected_target_project
......
...@@ -435,6 +435,18 @@ class Repository ...@@ -435,6 +435,18 @@ class Repository
end end
end end
def ff_merge(user, source_sha, target_branch, options = {})
our_commit = rugged.branches[target_branch].target
their_commit = rugged.lookup(source_sha)
raise "Invalid merge target" if our_commit.nil?
raise "Invalid merge source" if their_commit.nil?
commit_with_hooks(user, target_branch) do |ref|
source_sha
end
end
def merge(user, source_sha, target_branch, options = {}) def merge(user, source_sha, target_branch, options = {})
our_commit = rugged.branches[target_branch].target our_commit = rugged.branches[target_branch].target
their_commit = rugged.lookup(source_sha) their_commit = rugged.lookup(source_sha)
......
module MergeRequests
# MergeService class
#
# Do git merge and in case of success
# mark merge request as merged and execute all hooks and notifications
# Executed when you do merge via GitLab UI
#
class FfMergeService < MergeRequests::BaseService
attr_reader :merge_request
def execute(merge_request)
@merge_request = merge_request
unless @merge_request.ff_merge_possible?
return error('Merge request is not mergeable')
end
merge_request.in_locked_state do
if update_head
after_merge
success
else
error('Can not merge changes')
end
end
end
private
def update_head
repository.ff_merge(current_user, merge_request.source_sha, merge_request.target_branch)
end
def after_merge
MergeRequests::PostMergeService.new(project, current_user).execute(merge_request)
end
end
end
- if @status
:plain
location.reload()
- else
:plain
$('.mr-widget-body').html("#{escape_javascript(render('projects/merge_requests/widget/open/reload'))}");
...@@ -17,8 +17,8 @@ ...@@ -17,8 +17,8 @@
.accept-action .accept-action
= f.button class: "btn btn-reopen rebase-mr" do = f.button class: "btn btn-reopen rebase-mr" do
Rebase from #{@merge_request.target_branch} Rebase from #{@merge_request.target_branch}
.accept-control .accept-control
Fast-forward merge is not possible. Branch must be rebased first Fast-forward merge is not possible. Branch must be rebased first
:coffeescript :coffeescript
$('.accept-mr-form').on 'ajax:before', -> $('.accept-mr-form').on 'ajax:before', ->
......
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