Commit d6ed9920d68691472fe9f9a9247508573c64bae4

Authored by Zevs
1 parent 3b41b183

#888 prevent to remove source_branch

app/models/merge_request.rb
... ... @@ -189,7 +189,7 @@ class MergeRequest < ActiveRecord::Base
189 189 self.merge!(current_user.id)
190 190 true
191 191 end
192   - rescue
  192 + rescue
193 193 self.mark_as_unmergable
194 194 false
195 195 end
... ...
app/models/project/repository_trait.rb
... ... @@ -114,5 +114,9 @@ module Project::RepositoryTrait
114 114 def root_ref
115 115 default_branch || "master"
116 116 end
  117 +
  118 + def root_ref? branch
  119 + root_ref == branch
  120 + end
117 121 end
118 122 end
... ...
app/views/merge_requests/show.html.haml
... ... @@ -65,8 +65,9 @@
65 65 = form_for [:automerge, @project, @merge_request], :remote => true, :method => :get do |f|
66 66 You can accept this request automatically. If you still want to do it manually - #{link_to "click here", "#", :class => "how_to_merge_link vlink", :title => "How To Merge"} for instructions
67 67 %br
68   - = check_box_tag :should_remove_source_branch
69   - = label_tag :should_remove_source_branch, "Remove source-branch"
  68 + -unless @project.root_ref? @merge_request.source_branch
  69 + = check_box_tag :should_remove_source_branch
  70 + = label_tag :should_remove_source_branch, "Remove source-branch"
70 71  
71 72 = f.submit "Accept Merge Request", :class => "btn small info accept_merge_request"
72 73  
... ...
lib/gitlab/merge.rb
... ... @@ -50,7 +50,7 @@ module Gitlab
50 50 output = merge_repo.git.pull({}, "--no-ff", "origin", merge_request.source_branch)
51 51  
52 52 #remove source-branch
53   - if merge_request.should_remove_source_branch
  53 + if merge_request.should_remove_source_branch && !project.root_ref?(merge_request.source_branch)
54 54 merge_repo.git.sh "git push origin :#{merge_request.source_branch}"
55 55 end
56 56  
... ...