summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorZeger-Jan van de Weg <mail@zjvandeweg.nl>2016-02-04 11:51:12 +0100
committerZeger-Jan van de Weg <mail@zjvandeweg.nl>2016-02-04 11:56:23 +0100
commitc6e0228ca9937b10ad8e2620501d4fe221108d9a (patch)
tree4393a8699f98da3d172246f8d392589855d80fd7
parent8d948744461619ac3561be93d545d72343efa0cd (diff)
downloadgitlab-ce-c6e0228ca9937b10ad8e2620501d4fe221108d9a.tar.gz
Hide remove source branch button when new commit is added to branch
Fixes #3339 This MR hides the 'Remove source branch' button when a new commit is added to the source branch
-rw-r--r--CHANGELOG1
-rw-r--r--app/models/merge_request.rb3
-rw-r--r--spec/models/merge_request_spec.rb8
3 files changed, 10 insertions, 2 deletions
diff --git a/CHANGELOG b/CHANGELOG
index 481a0f8d243..a3c3fb67b19 100644
--- a/CHANGELOG
+++ b/CHANGELOG
@@ -28,6 +28,7 @@ v 8.5.0 (unreleased)
- Support Akismet spam checking for creation of issues via API (Stan Hu)
- Improve UI consistency between projects and groups lists
- Add sort dropdown to dashboard projects page
+ - Hide remove source branch button when the MR is merged but new commits are pushed (Zeger-Jan van de Weg)
v 8.4.3
- Increase lfs_objects size column to 8-byte integer to allow files larger
diff --git a/app/models/merge_request.rb b/app/models/merge_request.rb
index 89b6c49b362..00362352508 100644
--- a/app/models/merge_request.rb
+++ b/app/models/merge_request.rb
@@ -284,7 +284,8 @@ class MergeRequest < ActiveRecord::Base
def can_remove_source_branch?(current_user)
!source_project.protected_branch?(source_branch) &&
!source_project.root_ref?(source_branch) &&
- Ability.abilities.allowed?(current_user, :push_code, source_project)
+ Ability.abilities.allowed?(current_user, :push_code, source_project) &&
+ last_commit == source_project.commit(source_branch)
end
def mr_and_commit_notes
diff --git a/spec/models/merge_request_spec.rb b/spec/models/merge_request_spec.rb
index 46f2f20b986..f9d0e1029d6 100644
--- a/spec/models/merge_request_spec.rb
+++ b/spec/models/merge_request_spec.rb
@@ -226,9 +226,15 @@ describe MergeRequest, models: true do
expect(subject.can_remove_source_branch?(user2)).to be_falsey
end
- it "is can be removed in all other cases" do
+ it "can be removed if the last commit is the head of the source branch" do
+ allow(subject.source_project).to receive(:commit).and_return(subject.last_commit)
+
expect(subject.can_remove_source_branch?(user)).to be_truthy
end
+
+ it "cannot be removed if the last commit is not also the head of the source branch" do
+ expect(subject.can_remove_source_branch?(user)).to be_falsey
+ end
end
describe "#reset_merge_when_build_succeeds" do