Commit c0acc321 authored by Yorick Peterse's avatar Yorick Peterse

Merge branch 'fix-mr-cherry-pick-without-merge-commit' into 'master'

Verify the MR being displayed question has a merge commit set and can be cherry-picked

See merge request !3830
parent 223c64f8
......@@ -602,4 +602,8 @@ class MergeRequest < ActiveRecord::Base
def can_be_reverted?(current_user = nil)
merge_commit && !merge_commit.has_been_reverted?(current_user, self)
end
def can_be_cherry_picked?
merge_commit
end
end
......@@ -86,9 +86,9 @@
= spinner
= render 'shared/issuable/sidebar', issuable: @merge_request
- if @merge_request.can_be_reverted?
- if @merge_request.can_be_reverted?(current_user)
= render "projects/commit/change", type: 'revert', commit: @merge_request.merge_commit, title: @merge_request.title
- if @merge_request.merge_commit
- if @merge_request.can_be_cherry_picked?
= render "projects/commit/change", type: 'cherry-pick', commit: @merge_request.merge_commit, title: @merge_request.title
:javascript
......
......@@ -44,3 +44,8 @@
$('.remove_source_branch_in_progress').hide();
$('.remove_source_branch_widget.failed').show();
});
- else
%p
The changes were merged into
#{link_to @merge_request.target_branch, namespace_project_commits_path(@project.namespace, @project, @merge_request.target_branch), class: "label-branch"}.
= render 'projects/merge_requests/widget/merged_buttons'
- source_branch_exists = local_assigns.fetch(:source_branch_exists, false)
- mr_can_be_reverted = @merge_request.can_be_reverted?
- can_remove_source_branch = local_assigns.fetch(:source_branch_exists, false) && @merge_request.can_remove_source_branch?(current_user)
- mr_can_be_reverted = @merge_request.can_be_reverted?(current_user)
- mr_can_be_cherry_picked = @merge_request.can_be_cherry_picked?
- if source_branch_exists || mr_can_be_reverted
- if can_remove_source_branch || mr_can_be_reverted || mr_can_be_cherry_picked
.btn-group
- if source_branch_exists
- if can_remove_source_branch
= link_to namespace_project_branch_path(@merge_request.source_project.namespace, @merge_request.source_project, @merge_request.source_branch), remote: true, method: :delete, class: "btn btn-default btn-grouped btn-sm remove_source_branch" do
= icon('trash-o')
Remove Source Branch
- if mr_can_be_reverted
= revert_commit_link(@merge_request.merge_commit, namespace_project_merge_request_path(@project.namespace, @project, @merge_request), btn_class: 'sm')
- if mr_can_be_cherry_picked
= cherry_pick_commit_link(@merge_request.merge_commit, namespace_project_merge_request_path(@project.namespace, @project, @merge_request), btn_class: 'sm')
require 'spec_helper'
describe 'Cherry-pick Merge Requests' do
let(:user) { create(:user) }
let(:project) { create(:project) }
let(:merge_request) { create(:merge_request_with_diffs, source_project: project, author: user) }
before do
login_as user
project.team << [user, :master]
end
context "Viewing a merged merge request" do
before do
service = MergeRequests::MergeService.new(project, user)
perform_enqueued_jobs do
service.execute(merge_request)
end
end
# Fast-forward merge, or merged before GitLab 8.5.
context "Without a merge commit" do
before do
merge_request.merge_commit_sha = nil
merge_request.save
end
it "doesn't show a Cherry-pick button" do
visit namespace_project_merge_request_path(project.namespace, project, merge_request)
expect(page).not_to have_link "Cherry-pick"
end
end
context "With a merge commit" do
it "shows a Cherry-pick button" do
visit namespace_project_merge_request_path(project.namespace, project, merge_request)
expect(page).to have_link "Cherry-pick"
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