Commit 7d21d203 authored by Eric Eastwood's avatar Eric Eastwood

Move semi-linear merge strategy to CE area (mostly FE)

parent 33985a9c
...@@ -15,7 +15,7 @@ export default { ...@@ -15,7 +15,7 @@ export default {
showDisabledButton /> showDisabledButton />
<div class="media-body space-children"> <div class="media-body space-children">
<span <span
v-if="mr.ffOnlyEnabled" v-if="mr.shouldBeRebased"
class="bold"> class="bold">
Fast-forward merge is not possible. Fast-forward merge is not possible.
To merge this request, first rebase locally. To merge this request, first rebase locally.
......
...@@ -60,6 +60,7 @@ export default class MergeRequestStore { ...@@ -60,6 +60,7 @@ export default class MergeRequestStore {
this.mergeWhenPipelineSucceeds = data.merge_when_pipeline_succeeds || false; this.mergeWhenPipelineSucceeds = data.merge_when_pipeline_succeeds || false;
this.mergePath = data.merge_path; this.mergePath = data.merge_path;
this.ffOnlyEnabled = data.ff_only_enabled; this.ffOnlyEnabled = data.ff_only_enabled;
this.shouldBeRebased = !!data.should_be_rebased;
this.statusPath = data.status_path; this.statusPath = data.status_path;
this.emailPatchesPath = data.email_patches_path; this.emailPatchesPath = data.email_patches_path;
this.plainDiffPath = data.plain_diff_path; this.plainDiffPath = data.plain_diff_path;
......
...@@ -549,6 +549,14 @@ class MergeRequest < ActiveRecord::Base ...@@ -549,6 +549,14 @@ class MergeRequest < ActiveRecord::Base
true true
end end
def ff_merge_possible?
project.repository.ancestor?(target_branch_sha, diff_head_sha)
end
def should_be_rebased?
project.ff_merge_must_be_possible? && !ff_merge_possible?
end
def can_cancel_merge_when_pipeline_succeeds?(current_user) def can_cancel_merge_when_pipeline_succeeds?(current_user)
can_be_merged_by?(current_user) || self.author == current_user can_be_merged_by?(current_user) || self.author == current_user
end end
......
...@@ -1557,6 +1557,34 @@ class Project < ActiveRecord::Base ...@@ -1557,6 +1557,34 @@ class Project < ActiveRecord::Base
persisted? && path_changed? persisted? && path_changed?
end end
def merge_method
if self.merge_requests_ff_only_enabled
:ff
elsif self.merge_requests_rebase_enabled
:rebase_merge
else
:merge
end
end
def merge_method=(method)
case method.to_s
when "ff"
self.merge_requests_ff_only_enabled = true
self.merge_requests_rebase_enabled = true
when "rebase_merge"
self.merge_requests_ff_only_enabled = false
self.merge_requests_rebase_enabled = true
when "merge"
self.merge_requests_ff_only_enabled = false
self.merge_requests_rebase_enabled = false
end
end
def ff_merge_must_be_possible?
self.merge_requests_ff_only_enabled || self.merge_requests_rebase_enabled
end
private private
def storage def storage
......
- form = local_assigns.fetch(:form)
.radio
= label_tag :project_merge_method_rebase_merge do
= form.radio_button :merge_method, :rebase_merge, class: "js-merge-method-radio"
%strong Merge commit with semi-linear history
%br
%span.descr
A merge commit is created for every merge, but merging is only allowed if fast-forward merge is possible.
This way you could make sure that if this merge request would build, after merging to target branch it would also build.
%br
%span.descr
When fast-forward merge is not possible, the user must first rebase locally.
...@@ -11,6 +11,8 @@ ...@@ -11,6 +11,8 @@
%span.descr %span.descr
A merge commit is created for every merge, and merging is allowed as long as there are no conflicts. A merge commit is created for every merge, and merging is allowed as long as there are no conflicts.
= render 'merge_request_rebase_settings', form: form
= render 'merge_request_fast_forward_settings', project: @project, form: form = render 'merge_request_fast_forward_settings', project: @project, form: form
= render 'projects/merge_request_merge_settings', form: form = render 'projects/merge_request_merge_settings', form: form
...@@ -23,7 +23,6 @@ export default class MergeRequestStore extends CEMergeRequestStore { ...@@ -23,7 +23,6 @@ export default class MergeRequestStore extends CEMergeRequestStore {
} }
initRebase(data) { initRebase(data) {
this.shouldBeRebased = !!data.should_be_rebased;
this.canPushToSourceBranch = data.can_push_to_source_branch; this.canPushToSourceBranch = data.can_push_to_source_branch;
this.rebaseInProgress = data.rebase_in_progress; this.rebaseInProgress = data.rebase_in_progress;
this.approvalsLeft = !data.approved; this.approvalsLeft = !data.approved;
......
...@@ -13,16 +13,6 @@ module EE ...@@ -13,16 +13,6 @@ module EE
delegate :codeclimate_artifact, to: :base_pipeline, prefix: :base, allow_nil: true delegate :codeclimate_artifact, to: :base_pipeline, prefix: :base, allow_nil: true
end end
def ff_merge_possible?
project.repository.ancestor?(target_branch_sha, diff_head_sha)
end
def should_be_rebased?
project.feature_available?(:merge_request_rebase) &&
project.ff_merge_must_be_possible? &&
!ff_merge_possible?
end
def rebase_dir_path def rebase_dir_path
File.join(::Gitlab.config.shared.path, 'tmp/rebase', source_project.id.to_s, id.to_s).to_s File.join(::Gitlab.config.shared.path, 'tmp/rebase', source_project.id.to_s, id.to_s).to_s
end end
......
...@@ -11,8 +11,7 @@ ...@@ -11,8 +11,7 @@
%span.descr %span.descr
A merge commit is created for every merge, and merging is allowed as long as there are no conflicts. A merge commit is created for every merge, and merging is allowed as long as there are no conflicts.
- if @project.feature_available?(:merge_request_rebase) = render 'projects/ee/merge_request_rebase_settings', form: form
= render 'projects/ee/merge_request_rebase_settings', project: @project, form: form
= render 'projects/ee/merge_request_fast_forward_settings', project: @project, form: form = render 'projects/ee/merge_request_fast_forward_settings', project: @project, form: form
......
require 'spec_helper'
describe 'Edit Project Settings' do
let(:user) { create(:user) }
let(:project) { create(:project, namespace: user.namespace, path: 'gitlab', name: 'sample') }
before do
sign_in(user)
end
describe 'Merge request settings section' do
it 'shows "Merge commit with semi-linear history " strategy' do
visit edit_project_path(project)
page.within '.merge-requests-feature' do
expect(page).to have_content 'Merge commit with semi-linear history'
end
end
end
end
...@@ -41,6 +41,14 @@ describe 'Edit Project Settings' do ...@@ -41,6 +41,14 @@ describe 'Edit Project Settings' do
end end
end end
it 'shows "Merge commit with semi-linear history " strategy' do
visit edit_project_path(project)
page.within '.merge-requests-feature' do
expect(page).to have_content 'Merge commit with semi-linear history'
end
end
it 'shows "Fast-forward merge" strategy' do it 'shows "Fast-forward merge" strategy' do
visit edit_project_path(project) visit edit_project_path(project)
......
...@@ -81,13 +81,13 @@ describe('MRWidgetConflicts', () => { ...@@ -81,13 +81,13 @@ describe('MRWidgetConflicts', () => {
}); });
}); });
describe('when fast-forward merge enabled', () => { describe('when fast-forward or semi-linear merge enabled', () => {
let vm; let vm;
beforeEach(() => { beforeEach(() => {
vm = mountComponent(ConflictsComponent, { vm = mountComponent(ConflictsComponent, {
mr: { mr: {
ffOnlyEnabled: true, shouldBeRebased: true,
}, },
}); });
}); });
......
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