Commit 71b0f8ea0b7d4460fdbb70ca9b61789d37ed4885
1 parent
025e4157
Exists in
master
and in
4 other branches
Use existing methods for branch names: Ex use @repository.branch_names instead o…
…f @repository.heads.map(&:name)
Showing
5 changed files
with
32 additions
and
13 deletions
Show diff stats
app/controllers/merge_requests_controller.rb
... | ... | @@ -129,11 +129,11 @@ class MergeRequestsController < ProjectResourceController |
129 | 129 | |
130 | 130 | def validates_merge_request |
131 | 131 | # Show git not found page if target branch doesn't exist |
132 | - return invalid_mr unless @project.repo.heads.map(&:name).include?(@merge_request.target_branch) | |
132 | + return invalid_mr unless @project.repository.branch_names.include?(@merge_request.target_branch) | |
133 | 133 | |
134 | 134 | # Show git not found page if source branch doesn't exist |
135 | 135 | # and there is no saved commits between source & target branch |
136 | - return invalid_mr if !@project.repo.heads.map(&:name).include?(@merge_request.source_branch) && @merge_request.commits.blank? | |
136 | + return invalid_mr if !@project.repository.branch_names.include?(@merge_request.source_branch) && @merge_request.commits.blank? | |
137 | 137 | end |
138 | 138 | |
139 | 139 | def define_show_vars | ... | ... |
app/models/project.rb
... | ... | @@ -369,12 +369,19 @@ class Project < ActiveRecord::Base |
369 | 369 | end |
370 | 370 | |
371 | 371 | def open_branches |
372 | - if protected_branches.empty? | |
373 | - self.repo.heads | |
374 | - else | |
375 | - pnames = protected_branches.map(&:name) | |
376 | - self.repo.heads.reject { |h| pnames.include?(h.name) } | |
377 | - end.sort_by(&:name) | |
372 | + all_branches = repository.branches | |
373 | + | |
374 | + if protected_branches.present? | |
375 | + all_branches.reject! do |branch| | |
376 | + protected_branches_names.include?(branch.name) | |
377 | + end | |
378 | + end | |
379 | + | |
380 | + all_branches | |
381 | + end | |
382 | + | |
383 | + def protected_branches_names | |
384 | + @protected_branches_names ||= protected_branches.map(&:name) | |
378 | 385 | end |
379 | 386 | |
380 | 387 | def root_ref?(branch) |
... | ... | @@ -396,6 +403,6 @@ class Project < ActiveRecord::Base |
396 | 403 | |
397 | 404 | # Check if current branch name is marked as protected in the system |
398 | 405 | def protected_branch? branch_name |
399 | - protected_branches.map(&:name).include?(branch_name) | |
406 | + protected_branches_names.include?(branch_name) | |
400 | 407 | end |
401 | 408 | end | ... | ... |
app/models/repository.rb
app/views/merge_requests/_form.html.haml
... | ... | @@ -13,7 +13,7 @@ |
13 | 13 | .mr_branch_box |
14 | 14 | %h5.cgray From (Head Branch) |
15 | 15 | .body |
16 | - .padded= f.select(:source_branch, @repository.heads.map(&:name), { include_blank: "Select branch" }, {class: 'chosen span4'}) | |
16 | + .padded= f.select(:source_branch, @repository.branch_names, { include_blank: "Select branch" }, {class: 'chosen span4'}) | |
17 | 17 | .mr_source_commit |
18 | 18 | |
19 | 19 | .span2 |
... | ... | @@ -22,7 +22,7 @@ |
22 | 22 | .mr_branch_box |
23 | 23 | %h5.cgray To (Base Branch) |
24 | 24 | .body |
25 | - .padded= f.select(:target_branch, @repository.heads.map(&:name), { include_blank: "Select branch" }, {class: 'chosen span4'}) | |
25 | + .padded= f.select(:target_branch, @repository.branch_names, { include_blank: "Select branch" }, {class: 'chosen span4'}) | |
26 | 26 | .mr_target_commit |
27 | 27 | |
28 | 28 | %fieldset | ... | ... |
spec/models/project_spec.rb
... | ... | @@ -233,7 +233,7 @@ describe Project do |
233 | 233 | |
234 | 234 | it "should be true for projects with external issues tracker if issues enabled" do |
235 | 235 | ext_project.can_have_issues_tracker_id?.should be_true |
236 | - end | |
236 | + end | |
237 | 237 | |
238 | 238 | it "should be false for projects with internal issue tracker if issues enabled" do |
239 | 239 | project.can_have_issues_tracker_id?.should be_false |
... | ... | @@ -247,4 +247,15 @@ describe Project do |
247 | 247 | ext_project.can_have_issues_tracker_id?.should be_false |
248 | 248 | end |
249 | 249 | end |
250 | + | |
251 | + describe :open_branches do | |
252 | + let(:project) { create(:project) } | |
253 | + | |
254 | + before do | |
255 | + project.protected_branches.create(name: 'master') | |
256 | + end | |
257 | + | |
258 | + it { project.open_branches.map(&:name).should include('bootstrap') } | |
259 | + it { project.open_branches.map(&:name).should_not include('master') } | |
260 | + end | |
250 | 261 | end | ... | ... |