diff options
-rw-r--r-- | app/controllers/logs_controller.rb | 2 | ||||
-rw-r--r-- | app/controllers/trees_controller.rb | 2 | ||||
-rw-r--r-- | app/models/repository.rb | 6 | ||||
-rw-r--r-- | spec/models/repository_spec.rb | 8 |
4 files changed, 16 insertions, 2 deletions
diff --git a/app/controllers/logs_controller.rb b/app/controllers/logs_controller.rb index 6759793..a5d9ea6 100644 --- a/app/controllers/logs_controller.rb +++ b/app/controllers/logs_controller.rb @@ -20,7 +20,7 @@ class LogsController < ApplicationController before_filter :check_repository_for_commits def index - redirect_to project_repository_log_path(@project, @repository, @repository.head_candidate.name) + redirect_to project_repository_log_path(@project, @repository, @repository.head_candidate_name) end def show diff --git a/app/controllers/trees_controller.rb b/app/controllers/trees_controller.rb index 1f8ca3a..d452b0a 100644 --- a/app/controllers/trees_controller.rb +++ b/app/controllers/trees_controller.rb @@ -21,7 +21,7 @@ class TreesController < ApplicationController def index redirect_to(project_repository_tree_path(@project, @repository, - @repository.head_candidate.name, [])) + @repository.head_candidate_name, [])) end def show diff --git a/app/models/repository.rb b/app/models/repository.rb index 878290e..9906d87 100644 --- a/app/models/repository.rb +++ b/app/models/repository.rb @@ -134,6 +134,12 @@ class Repository < ActiveRecord::Base @head_candidate ||= git.heads.find{|h| h.name == "master"} || git.heads.first end + def head_candidate_name + if head = head_candidate + head.name.include?("/") ? head.commit.id : head.name + end + end + def last_commit if has_commits? @last_commit ||= git.commits(head_candidate.name, 1).first diff --git a/spec/models/repository_spec.rb b/spec/models/repository_spec.rb index 015ae24..e6eeb1d 100644 --- a/spec/models/repository_spec.rb +++ b/spec/models/repository_spec.rb @@ -300,6 +300,14 @@ describe Repository do @repository.head_candidate.should == heads_stub end + it "has a head_candidate_name that returns the commit id if the branch contains slashes" do + heads_stub = mock("head") + heads_stub.stub!(:name).and_return("foo/bar") + heads_stub.stub!(:commit).and_return(mock("commit", :id => "asdf1234")) + @repository.should_receive(:head_candidate).and_return(heads_stub) + @repository.head_candidate_name.should == "asdf1234" + end + it "has a head_candidate, unless it doesn't have commits" do @repository.should_receive(:has_commits?).and_return(false) @repository.head_candidate.should == nil |