From a73f68a185df00db1aaa153f576f106ee752c54d Mon Sep 17 00:00:00 2001 From: Jean-Philippe Lang Date: Sun, 27 Apr 2008 10:12:15 +0000 Subject: [PATCH] Fixed: Links to repository directories don't work (#1119). git-svn-id: http://redmine.rubyforge.org/svn/trunk@1365 e93f8b46-1217-0410-a6f0-8f06a7374b81 --- app/controllers/repositories_controller.rb | 9 ++++++++- lib/redmine/scm/adapters/abstract_adapter.rb | 13 +++++++++++-- lib/redmine/scm/adapters/bazaar_adapter.rb | 12 ------------ lib/redmine/scm/adapters/cvs_adapter.rb | 9 --------- lib/redmine/scm/adapters/darcs_adapter.rb | 7 ------- lib/redmine/scm/adapters/git_adapter.rb | 8 -------- lib/redmine/scm/adapters/mercurial_adapter.rb | 8 -------- lib/redmine/scm/adapters/subversion_adapter.rb | 7 ------- .../repositories_bazaar_controller_test.rb | 8 ++++++++ test/functional/repositories_cvs_controller_test.rb | 8 ++++++++ test/functional/repositories_git_controller_test.rb | 8 ++++++++ .../repositories_mercurial_controller_test.rb | 10 +++++++++- .../repositories_subversion_controller_test.rb | 8 ++++++++ 13 files changed, 60 insertions(+), 55 deletions(-) diff --git a/app/controllers/repositories_controller.rb b/app/controllers/repositories_controller.rb index 198a9766c..64eb05793 100644 --- a/app/controllers/repositories_controller.rb +++ b/app/controllers/repositories_controller.rb @@ -65,7 +65,8 @@ class RepositoriesController < ApplicationController if request.xhr? @entries ? render(:partial => 'dir_list_content') : render(:nothing => true) else - show_error_not_found unless @entries + show_error_not_found and return unless @entries + render :action => 'browse' end rescue Redmine::Scm::Adapters::CommandFailed => e show_error_command_failed(e.message) @@ -95,6 +96,12 @@ class RepositoriesController < ApplicationController end def entry + @entry = @repository.scm.entry(@path, @rev) + show_error_not_found and return unless @entry + + # If the entry is a dir, show the browser + browse and return if @entry.is_dir? + @content = @repository.scm.cat(@path, @rev) show_error_not_found and return unless @content if 'raw' == params[:format] || @content.is_binary_data? diff --git a/lib/redmine/scm/adapters/abstract_adapter.rb b/lib/redmine/scm/adapters/abstract_adapter.rb index 41edf00ad..2c254d48d 100644 --- a/lib/redmine/scm/adapters/abstract_adapter.rb +++ b/lib/redmine/scm/adapters/abstract_adapter.rb @@ -59,8 +59,17 @@ module Redmine # Returns the entry identified by path and revision identifier # or nil if entry doesn't exist in the repository def entry(path=nil, identifier=nil) - e = entries(path, identifier) - e ? e.first : nil + parts = path.to_s.split(%r{[\/\\]}).select {|n| !n.blank?} + search_path = parts[0..-2].join('/') + search_name = parts[-1] + if search_path.blank? && search_name.blank? + # Root entry + Entry.new(:path => '', :kind => 'dir') + else + # Search for the entry in the parent directory + es = entries(search_path, identifier) + es ? es.detect {|e| e.name == search_name} : nil + end end # Returns an Entries collection diff --git a/lib/redmine/scm/adapters/bazaar_adapter.rb b/lib/redmine/scm/adapters/bazaar_adapter.rb index 11a44b7cf..2225a627c 100644 --- a/lib/redmine/scm/adapters/bazaar_adapter.rb +++ b/lib/redmine/scm/adapters/bazaar_adapter.rb @@ -44,18 +44,6 @@ module Redmine return nil end - # Returns the entry identified by path and revision identifier - # or nil if entry doesn't exist in the repository - def entry(path=nil, identifier=nil) - path ||= '' - parts = path.split(%r{[\/\\]}).select {|p| !p.blank?} - if parts.size > 0 - parent = parts[0..-2].join('/') - entries = entries(parent, identifier) - entries ? entries.detect {|e| e.name == parts.last} : nil - end - end - # Returns an Entries collection # or nil if the given path doesn't exist in the repository def entries(path=nil, identifier=nil) diff --git a/lib/redmine/scm/adapters/cvs_adapter.rb b/lib/redmine/scm/adapters/cvs_adapter.rb index 6085bfdbe..37920b599 100644 --- a/lib/redmine/scm/adapters/cvs_adapter.rb +++ b/lib/redmine/scm/adapters/cvs_adapter.rb @@ -55,15 +55,6 @@ module Redmine def get_previous_revision(revision) CvsRevisionHelper.new(revision).prevRev end - - # Returns the entry identified by path and revision identifier - # or nil if entry doesn't exist in the repository - # this method returns all revisions from one single SCM-Entry - def entry(path=nil, identifier="HEAD") - e = entries(path, identifier) - logger.debug(" #{e.first.inspect}") if e - e ? e.first : nil - end # Returns an Entries collection # or nil if the given path doesn't exist in the repository diff --git a/lib/redmine/scm/adapters/darcs_adapter.rb b/lib/redmine/scm/adapters/darcs_adapter.rb index 660b6cf8f..a1d1867b1 100644 --- a/lib/redmine/scm/adapters/darcs_adapter.rb +++ b/lib/redmine/scm/adapters/darcs_adapter.rb @@ -40,13 +40,6 @@ module Redmine rev ? Info.new({:root_url => @url, :lastrev => rev.last}) : nil end - # Returns the entry identified by path and revision identifier - # or nil if entry doesn't exist in the repository - def entry(path=nil, identifier=nil) - e = entries(path, identifier) - e ? e.first : nil - end - # Returns an Entries collection # or nil if the given path doesn't exist in the repository def entries(path=nil, identifier=nil) diff --git a/lib/redmine/scm/adapters/git_adapter.rb b/lib/redmine/scm/adapters/git_adapter.rb index 5d315b0cc..77604f283 100644 --- a/lib/redmine/scm/adapters/git_adapter.rb +++ b/lib/redmine/scm/adapters/git_adapter.rb @@ -132,14 +132,6 @@ module Redmine entries.sort_by_name end - def entry(path=nil, identifier=nil) - path ||= '' - search_path = path.split('/')[0..-2].join('/') - entry_name = path.split('/').last - e = entries(search_path, identifier) - e ? e.detect{|entry| entry.name == entry_name} : nil - end - def revisions(path, identifier_from, identifier_to, options={}) revisions = Revisions.new cmd = "#{GIT_BIN} --git-dir #{target('')} log --raw " diff --git a/lib/redmine/scm/adapters/mercurial_adapter.rb b/lib/redmine/scm/adapters/mercurial_adapter.rb index 72db723ba..6f42dda06 100644 --- a/lib/redmine/scm/adapters/mercurial_adapter.rb +++ b/lib/redmine/scm/adapters/mercurial_adapter.rb @@ -59,14 +59,6 @@ module Redmine return nil if $? && $?.exitstatus != 0 entries.sort_by_name end - - def entry(path=nil, identifier=nil) - path ||= '' - search_path = path.split('/')[0..-2].join('/') - entry_name = path.split('/').last - e = entries(search_path, identifier) - e ? e.detect{|entry| entry.name == entry_name} : nil - end def revisions(path=nil, identifier_from=nil, identifier_to=nil, options={}) revisions = Revisions.new diff --git a/lib/redmine/scm/adapters/subversion_adapter.rb b/lib/redmine/scm/adapters/subversion_adapter.rb index efbd3ba8e..40c7eb3f1 100644 --- a/lib/redmine/scm/adapters/subversion_adapter.rb +++ b/lib/redmine/scm/adapters/subversion_adapter.rb @@ -51,13 +51,6 @@ module Redmine return nil end - # Returns the entry identified by path and revision identifier - # or nil if entry doesn't exist in the repository - def entry(path=nil, identifier=nil) - e = entries(path, identifier) - e ? e.first : nil - end - # Returns an Entries collection # or nil if the given path doesn't exist in the repository def entries(path=nil, identifier=nil) diff --git a/test/functional/repositories_bazaar_controller_test.rb b/test/functional/repositories_bazaar_controller_test.rb index 5a473bab3..acb6c1d21 100644 --- a/test/functional/repositories_bazaar_controller_test.rb +++ b/test/functional/repositories_bazaar_controller_test.rb @@ -99,6 +99,14 @@ class RepositoriesBazaarControllerTest < Test::Unit::TestCase assert @response.body.include?('Show help message') end + def test_directory_entry + get :entry, :id => 3, :path => ['directory'] + assert_response :success + assert_template 'browse' + assert_not_nil assigns(:entry) + assert_equal 'directory', assigns(:entry).name + end + def test_diff # Full diff of changeset 3 get :diff, :id => 3, :rev => 3 diff --git a/test/functional/repositories_cvs_controller_test.rb b/test/functional/repositories_cvs_controller_test.rb index d6181ad36..e12bb53ac 100644 --- a/test/functional/repositories_cvs_controller_test.rb +++ b/test/functional/repositories_cvs_controller_test.rb @@ -101,6 +101,14 @@ class RepositoriesCvsControllerTest < Test::Unit::TestCase get :entry, :id => 1, :path => ['sources', 'watchers_controller.rb'], :format => 'raw' assert_response :success end + + def test_directory_entry + get :entry, :id => 1, :path => ['sources'] + assert_response :success + assert_template 'browse' + assert_not_nil assigns(:entry) + assert_equal 'sources', assigns(:entry).name + end def test_diff Project.find(1).repository.fetch_changesets diff --git a/test/functional/repositories_git_controller_test.rb b/test/functional/repositories_git_controller_test.rb index 10a4950f3..339e22897 100644 --- a/test/functional/repositories_git_controller_test.rb +++ b/test/functional/repositories_git_controller_test.rb @@ -101,6 +101,14 @@ class RepositoriesGitControllerTest < Test::Unit::TestCase assert @response.body.include?('WITHOUT ANY WARRANTY') end + def test_directory_entry + get :entry, :id => 3, :path => ['sources'] + assert_response :success + assert_template 'browse' + assert_not_nil assigns(:entry) + assert_equal 'sources', assigns(:entry).name + end + def test_diff # Full diff of changeset 2f9c0091 get :diff, :id => 3, :rev => '2f9c0091c754a91af7a9c478e36556b4bde8dcf7' diff --git a/test/functional/repositories_mercurial_controller_test.rb b/test/functional/repositories_mercurial_controller_test.rb index b09265d13..cb870aa32 100644 --- a/test/functional/repositories_mercurial_controller_test.rb +++ b/test/functional/repositories_mercurial_controller_test.rb @@ -99,7 +99,15 @@ class RepositoriesMercurialControllerTest < Test::Unit::TestCase # File content assert @response.body.include?('WITHOUT ANY WARRANTY') end - + + def test_directory_entry + get :entry, :id => 3, :path => ['sources'] + assert_response :success + assert_template 'browse' + assert_not_nil assigns(:entry) + assert_equal 'sources', assigns(:entry).name + end + def test_diff # Full diff of changeset 4 get :diff, :id => 3, :rev => 4 diff --git a/test/functional/repositories_subversion_controller_test.rb b/test/functional/repositories_subversion_controller_test.rb index adb69c8e9..dd56947fc 100644 --- a/test/functional/repositories_subversion_controller_test.rb +++ b/test/functional/repositories_subversion_controller_test.rb @@ -89,6 +89,14 @@ class RepositoriesSubversionControllerTest < Test::Unit::TestCase assert_response :success end + def test_directory_entry + get :entry, :id => 1, :path => ['subversion_test', 'folder'] + assert_response :success + assert_template 'browse' + assert_not_nil assigns(:entry) + assert_equal 'folder', assigns(:entry).name + end + def test_diff get :diff, :id => 1, :rev => 3 assert_response :success