]> source.dussan.org Git - redmine.git/commitdiff
Fixed: Links to repository directories don't work (#1119).
authorJean-Philippe Lang <jp_lang@yahoo.fr>
Sun, 27 Apr 2008 10:12:15 +0000 (10:12 +0000)
committerJean-Philippe Lang <jp_lang@yahoo.fr>
Sun, 27 Apr 2008 10:12:15 +0000 (10:12 +0000)
git-svn-id: http://redmine.rubyforge.org/svn/trunk@1365 e93f8b46-1217-0410-a6f0-8f06a7374b81

13 files changed:
app/controllers/repositories_controller.rb
lib/redmine/scm/adapters/abstract_adapter.rb
lib/redmine/scm/adapters/bazaar_adapter.rb
lib/redmine/scm/adapters/cvs_adapter.rb
lib/redmine/scm/adapters/darcs_adapter.rb
lib/redmine/scm/adapters/git_adapter.rb
lib/redmine/scm/adapters/mercurial_adapter.rb
lib/redmine/scm/adapters/subversion_adapter.rb
test/functional/repositories_bazaar_controller_test.rb
test/functional/repositories_cvs_controller_test.rb
test/functional/repositories_git_controller_test.rb
test/functional/repositories_mercurial_controller_test.rb
test/functional/repositories_subversion_controller_test.rb

index 198a9766c9ae01a9f1a2e38419c77f6cdf133270..64eb05793e9f306fcaee6c8128a79e4cd5be9028 100644 (file)
@@ -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?
index 41edf00add8362fafb639b6c066b23fc93f592b3..2c254d48d26d6c8eb995b552c75be3aa5bc62cda 100644 (file)
@@ -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
index 11a44b7cfb0a8c175db7835625231fd53f3d9c64..2225a627c484eeec676442580a412b25e3ae082b 100644 (file)
@@ -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)
index 6085bfdbe3a8461194b662fda538c5fb5d0165bf..37920b599dad0818e5a222d73f42818a66a79207 100644 (file)
@@ -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("<cvs-result> #{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
index 660b6cf8f979057a5e25fa89a0ee037b02548bad..a1d1867b1540d56465d6d93b93e20fb3692164a4 100644 (file)
@@ -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)
index 5d315b0cc2486b6d03cdfefb9d753eff3eae7f12..77604f283e8fd29d0d949b9a65571161ad92d7f2 100644 (file)
@@ -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 "
index 72db723ba9e57d2ee96730971948acbcbb055559..6f42dda06f88ca9e7e5612c7ba80b61f0e9b6349 100644 (file)
@@ -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
index efbd3ba8e174e6559d22ff4126a1023688b97527..40c7eb3f14c25afca2ab10ce6030f23e56f7fe27 100644 (file)
@@ -51,13 +51,6 @@ module Redmine
           return nil\r
         end\r
         \r
-        # Returns the entry identified by path and revision identifier\r
-        # or nil if entry doesn't exist in the repository\r
-        def entry(path=nil, identifier=nil)\r
-          e = entries(path, identifier)\r
-          e ? e.first : nil\r
-        end\r
-        \r
         # Returns an Entries collection\r
         # or nil if the given path doesn't exist in the repository\r
         def entries(path=nil, identifier=nil)\r
index 5a473bab3d3ff08616f342dc1a5cf1db2649bb43..acb6c1d21b8ca3122916bd09cd471cac7403386c 100644 (file)
@@ -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
index d6181ad36c0f483b4dfd6949511d4905291c3dc2..e12bb53acfc33d794673c68e2d2ce23613fc5871 100644 (file)
@@ -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
index 10a4950f3abc74939ae6253606058ba8db78c6b0..339e22897e9faa14b185c29da5c015ead2b40cd8 100644 (file)
@@ -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'
index b09265d133127d5443cac6f83502bef261e74440..cb870aa326765819590a8c7494d6be4abc9622ca 100644 (file)
@@ -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
index adb69c8e9c41fb88e57965dadee8bbd75d985a9e..dd56947fc687385990c8f81bf8cd694d5851ad67 100644 (file)
@@ -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