summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--app/roles/repository.rb14
-rw-r--r--spec/roles/repository_spec.rb8
2 files changed, 11 insertions, 11 deletions
diff --git a/app/roles/repository.rb b/app/roles/repository.rb
index 191a6d70221..e7e57b0e0c9 100644
--- a/app/roles/repository.rb
+++ b/app/roles/repository.rb
@@ -46,18 +46,18 @@ module Repository
end
# Returns an Array of branch names
- def branches
+ def branch_names
repo.branches.collect(&:name).sort
end
# Returns an Array of tag names
- def tags
+ def tag_names
repo.tags.collect(&:name).sort.reverse
end
# Returns an Array of branch and tag names
def ref_names
- [branches + tags].flatten
+ [branch_names + tag_names].flatten
end
def repo
@@ -112,12 +112,12 @@ module Repository
# - If two or more branches are present, returns the one that has a name
# matching root_ref (default_branch or 'master' if default_branch is nil)
def discover_default_branch
- if branches.length == 0
+ if branch_names.length == 0
nil
- elsif branches.length == 1
- branches.first
+ elsif branch_names.length == 1
+ branch_names.first
else
- branches.select { |v| v == root_ref }.first
+ branch_names.select { |v| v == root_ref }.first
end
end
diff --git a/spec/roles/repository_spec.rb b/spec/roles/repository_spec.rb
index c4e0e9dec81..3507585aa8d 100644
--- a/spec/roles/repository_spec.rb
+++ b/spec/roles/repository_spec.rb
@@ -25,23 +25,23 @@ describe Project, "Repository" do
let(:stable) { 'stable' }
it "returns 'master' when master exists" do
- project.should_receive(:branches).at_least(:once).and_return([stable, master])
+ project.should_receive(:branch_names).at_least(:once).and_return([stable, master])
project.discover_default_branch.should == 'master'
end
it "returns non-master when master exists but default branch is set to something else" do
project.default_branch = 'stable'
- project.should_receive(:branches).at_least(:once).and_return([stable, master])
+ project.should_receive(:branch_names).at_least(:once).and_return([stable, master])
project.discover_default_branch.should == 'stable'
end
it "returns a non-master branch when only one exists" do
- project.should_receive(:branches).at_least(:once).and_return([stable])
+ project.should_receive(:branch_names).at_least(:once).and_return([stable])
project.discover_default_branch.should == 'stable'
end
it "returns nil when no branch exists" do
- project.should_receive(:branches).at_least(:once).and_return([])
+ project.should_receive(:branch_names).at_least(:once).and_return([])
project.discover_default_branch.should be_nil
end
end