Commit 71b0f8ea authored by Dmitriy Zaporozhets's avatar Dmitriy Zaporozhets

Use existing methods for branch names: Ex use @repository.branch_names instead...

Use existing methods for branch names: Ex use @repository.branch_names instead of @repository.heads.map(&:name)
parent 025e4157
...@@ -129,11 +129,11 @@ class MergeRequestsController < ProjectResourceController ...@@ -129,11 +129,11 @@ class MergeRequestsController < ProjectResourceController
def validates_merge_request def validates_merge_request
# Show git not found page if target branch doesn't exist # Show git not found page if target branch doesn't exist
return invalid_mr unless @project.repo.heads.map(&:name).include?(@merge_request.target_branch) return invalid_mr unless @project.repository.branch_names.include?(@merge_request.target_branch)
# Show git not found page if source branch doesn't exist # Show git not found page if source branch doesn't exist
# and there is no saved commits between source & target branch # and there is no saved commits between source & target branch
return invalid_mr if !@project.repo.heads.map(&:name).include?(@merge_request.source_branch) && @merge_request.commits.blank? return invalid_mr if !@project.repository.branch_names.include?(@merge_request.source_branch) && @merge_request.commits.blank?
end end
def define_show_vars def define_show_vars
......
...@@ -369,12 +369,19 @@ class Project < ActiveRecord::Base ...@@ -369,12 +369,19 @@ class Project < ActiveRecord::Base
end end
def open_branches def open_branches
if protected_branches.empty? all_branches = repository.branches
self.repo.heads
else if protected_branches.present?
pnames = protected_branches.map(&:name) all_branches.reject! do |branch|
self.repo.heads.reject { |h| pnames.include?(h.name) } protected_branches_names.include?(branch.name)
end.sort_by(&:name) end
end
all_branches
end
def protected_branches_names
@protected_branches_names ||= protected_branches.map(&:name)
end end
def root_ref?(branch) def root_ref?(branch)
...@@ -396,6 +403,6 @@ class Project < ActiveRecord::Base ...@@ -396,6 +403,6 @@ class Project < ActiveRecord::Base
# Check if current branch name is marked as protected in the system # Check if current branch name is marked as protected in the system
def protected_branch? branch_name def protected_branch? branch_name
protected_branches.map(&:name).include?(branch_name) protected_branches_names.include?(branch_name)
end end
end end
...@@ -63,8 +63,9 @@ class Repository ...@@ -63,8 +63,9 @@ class Repository
end end
# Returns an Array of branch names # Returns an Array of branch names
# sorted by name ASC
def branch_names def branch_names
repo.branches.collect(&:name).sort branches.map(&:name)
end end
# Returns an Array of Branches # Returns an Array of Branches
......
...@@ -13,7 +13,7 @@ ...@@ -13,7 +13,7 @@
.mr_branch_box .mr_branch_box
%h5.cgray From (Head Branch) %h5.cgray From (Head Branch)
.body .body
.padded= f.select(:source_branch, @repository.heads.map(&:name), { include_blank: "Select branch" }, {class: 'chosen span4'}) .padded= f.select(:source_branch, @repository.branch_names, { include_blank: "Select branch" }, {class: 'chosen span4'})
.mr_source_commit .mr_source_commit
.span2 .span2
...@@ -22,7 +22,7 @@ ...@@ -22,7 +22,7 @@
.mr_branch_box .mr_branch_box
%h5.cgray To (Base Branch) %h5.cgray To (Base Branch)
.body .body
.padded= f.select(:target_branch, @repository.heads.map(&:name), { include_blank: "Select branch" }, {class: 'chosen span4'}) .padded= f.select(:target_branch, @repository.branch_names, { include_blank: "Select branch" }, {class: 'chosen span4'})
.mr_target_commit .mr_target_commit
%fieldset %fieldset
......
...@@ -247,4 +247,15 @@ describe Project do ...@@ -247,4 +247,15 @@ describe Project do
ext_project.can_have_issues_tracker_id?.should be_false ext_project.can_have_issues_tracker_id?.should be_false
end end
end end
describe :open_branches do
let(:project) { create(:project) }
before do
project.protected_branches.create(name: 'master')
end
it { project.open_branches.map(&:name).should include('bootstrap') }
it { project.open_branches.map(&:name).should_not include('master') }
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