Commit d34733ef authored by Rubén Dávila's avatar Rubén Dávila Committed by Robert Speicher

Don't show revert button if commit/MR has already been reverted.

parent e8d15f13
...@@ -219,14 +219,20 @@ class Commit ...@@ -219,14 +219,20 @@ class Commit
"revert-#{short_id}" "revert-#{short_id}"
end end
def revert_message def revert_description
description = if merged_merge_request if merged_merge_request
"This reverts merge request #{merged_merge_request.to_reference}" "This reverts merge request #{merged_merge_request.to_reference}"
else else
"This reverts commit #{sha}" "This reverts commit #{sha}"
end end
end
def revert_message
"Revert \"#{title}\"" + "\n\n#{revert_description}"
end
"Revert \"#{title}\"" + "\n\n#{description}" def reverts_commit?(commit)
description.include?(commit.revert_description)
end end
def merge_commit? def merge_commit?
...@@ -239,6 +245,14 @@ class Commit ...@@ -239,6 +245,14 @@ class Commit
@merged_merge_request = merge_commit? && MergeRequest.find_by(merge_commit_sha: id) @merged_merge_request = merge_commit? && MergeRequest.find_by(merge_commit_sha: id)
end end
def has_been_reverted?(current_user = nil, noteable = self)
Gitlab::ReferenceExtractor.lazily do
[self, *noteable.notes].flat_map do |note|
note.all_references(current_user).commits
end
end.any? { |commit_ref| commit_ref.reverts_commit?(self) }
end
private private
def repo_changes def repo_changes
......
...@@ -533,4 +533,14 @@ class MergeRequest < ActiveRecord::Base ...@@ -533,4 +533,14 @@ class MergeRequest < ActiveRecord::Base
[diff_base_commit, last_commit] [diff_base_commit, last_commit]
end end
def merge_commit
@merge_commit ||= project.commit(merge_commit_sha) if merge_commit_sha
end
def has_been_reverted?(current_user = nil)
if merge_commit
merge_commit.has_been_reverted?(current_user, self)
end
end
end end
...@@ -16,6 +16,7 @@ ...@@ -16,6 +16,7 @@
= link_to namespace_project_tree_path(@project.namespace, @project, @commit), class: "btn btn-grouped" do = link_to namespace_project_tree_path(@project.namespace, @project, @commit), class: "btn btn-grouped" do
= icon('files-o') = icon('files-o')
Browse Files Browse Files
- unless @commit.has_been_reverted?(current_user)
= revert_commit_link(namespace_project_commit_path(@project.namespace, @project, @commit.id)) = revert_commit_link(namespace_project_commit_path(@project.namespace, @project, @commit.id))
%div %div
......
...@@ -85,8 +85,8 @@ ...@@ -85,8 +85,8 @@
= spinner = spinner
= render 'shared/issuable/sidebar', issuable: @merge_request = render 'shared/issuable/sidebar', issuable: @merge_request
- if @merge_request.merge_commit_sha - if @merge_request.merge_commit && !@merge_request.has_been_reverted?(current_user)
= render "projects/commit/revert", commit_id: @merge_request.merge_commit_sha, title: @merge_request.title = render "projects/commit/revert", commit_id: @merge_request.merge_commit.id, title: @merge_request.title
:javascript :javascript
var merge_request; var merge_request;
......
...@@ -6,7 +6,7 @@ ...@@ -6,7 +6,7 @@
- if @merge_request.merge_event - if @merge_request.merge_event
by #{link_to_member(@project, @merge_request.merge_event.author, avatar: true)} by #{link_to_member(@project, @merge_request.merge_event.author, avatar: true)}
#{time_ago_with_tooltip(@merge_request.merge_event.created_at)} #{time_ago_with_tooltip(@merge_request.merge_event.created_at)}
- if @merge_request.merge_commit_sha.present? - unless @merge_request.has_been_reverted?(current_user)
= revert_commit_link(namespace_project_merge_request_path(@project.namespace, @project, @merge_request), btn_class: 'sm') = revert_commit_link(namespace_project_merge_request_path(@project.namespace, @project, @merge_request), btn_class: 'sm')
%div %div
- if !@merge_request.source_branch_exists? || (params[:delete_source] == 'true') - if !@merge_request.source_branch_exists? || (params[:delete_source] == '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