]> source.dussan.org Git - redmine.git/commitdiff
Support listing directories in svn which include square brackets. #5548
authorEric Davis <edavis@littlestreamsoftware.com>
Sun, 20 Jun 2010 16:08:26 +0000 (16:08 +0000)
committerEric Davis <edavis@littlestreamsoftware.com>
Sun, 20 Jun 2010 16:08:26 +0000 (16:08 +0000)
Contributed by Gregor Schmidt

git-svn-id: svn+ssh://rubyforge.org/var/svn/redmine/trunk@3800 e93f8b46-1217-0410-a6f0-8f06a7374b81

lib/redmine/scm/adapters/subversion_adapter.rb
test/fixtures/repositories/subversion_repository.dump.gz
test/functional/repositories_subversion_controller_test.rb
test/unit/repository_subversion_test.rb

index 73814f9398c0d124c96d0c960ce0191e80e91f0b..a4520a62ef0851e75bfdfc66c671de5fad26852c 100644 (file)
@@ -47,7 +47,7 @@ module Redmine
         \r
         # Get info about the svn repository\r
         def info\r
-          cmd = "#{SVN_BIN} info --xml #{target('')}"\r
+          cmd = "#{SVN_BIN} info --xml #{target}"\r
           cmd << credentials_string\r
           info = nil\r
           shellout(cmd) do |io|\r
@@ -77,7 +77,7 @@ module Redmine
           path ||= ''\r
           identifier = (identifier and identifier.to_i > 0) ? identifier.to_i : "HEAD"\r
           entries = Entries.new\r
-          cmd = "#{SVN_BIN} list --xml #{target(URI.escape(path))}@#{identifier}"\r
+          cmd = "#{SVN_BIN} list --xml #{target(path)}@#{identifier}"\r
           cmd << credentials_string\r
           shellout(cmd) do |io|\r
             output = io.read\r
@@ -116,7 +116,7 @@ module Redmine
           return nil unless self.class.client_version_above?([1, 5, 0])\r
           \r
           identifier = (identifier and identifier.to_i > 0) ? identifier.to_i : "HEAD"\r
-          cmd = "#{SVN_BIN} proplist --verbose --xml #{target(URI.escape(path))}@#{identifier}"\r
+          cmd = "#{SVN_BIN} proplist --verbose --xml #{target(path)}@#{identifier}"\r
           cmd << credentials_string\r
           properties = {}\r
           shellout(cmd) do |io|\r
@@ -142,7 +142,7 @@ module Redmine
           cmd << credentials_string\r
           cmd << " --verbose " if  options[:with_paths]\r
           cmd << " --limit #{options[:limit].to_i}" if options[:limit]\r
-          cmd << ' ' + target(URI.escape(path))\r
+          cmd << ' ' + target(path)\r
           shellout(cmd) do |io|\r
             output = io.read\r
             begin\r
@@ -180,7 +180,7 @@ module Redmine
           cmd = "#{SVN_BIN} diff -r "\r
           cmd << "#{identifier_to}:"\r
           cmd << "#{identifier_from}"\r
-          cmd << " #{target(URI.escape(path))}@#{identifier_from}"\r
+          cmd << " #{target(path)}@#{identifier_from}"\r
           cmd << credentials_string\r
           diff = []\r
           shellout(cmd) do |io|\r
@@ -194,7 +194,7 @@ module Redmine
         \r
         def cat(path, identifier=nil)\r
           identifier = (identifier and identifier.to_i > 0) ? identifier.to_i : "HEAD"\r
-          cmd = "#{SVN_BIN} cat #{target(URI.escape(path))}@#{identifier}"\r
+          cmd = "#{SVN_BIN} cat #{target(path)}@#{identifier}"\r
           cmd << credentials_string\r
           cat = nil\r
           shellout(cmd) do |io|\r
@@ -207,7 +207,7 @@ module Redmine
         \r
         def annotate(path, identifier=nil)\r
           identifier = (identifier and identifier.to_i > 0) ? identifier.to_i : "HEAD"\r
-          cmd = "#{SVN_BIN} blame #{target(URI.escape(path))}@#{identifier}"\r
+          cmd = "#{SVN_BIN} blame #{target(path)}@#{identifier}"\r
           cmd << credentials_string\r
           blame = Annotate.new\r
           shellout(cmd) do |io|\r
@@ -243,6 +243,13 @@ module Redmine
             end\r
           end\r
         end\r
+\r
+        def target(path = '')\r
+          base = path.match(/^\//) ? root_url : url\r
+          uri = "#{base}/#{path}"\r
+          uri = URI.escape(URI.escape(uri), '[]')\r
+          shell_quote(uri.gsub(/[?<>\*]/, ''))\r
+        end\r
       end\r
     end\r
   end\r
index 79ef77fa7dc420f0715028a8e201901dbc66d4c1..b47542f174432006c3faa6affbe4d45954064f9a 100644 (file)
Binary files a/test/fixtures/repositories/subversion_repository.dump.gz and b/test/fixtures/repositories/subversion_repository.dump.gz differ
index d28646d44f46607d1e423f89206f85ed2ea991f1..7c88f253224e1badc1b5debdbdc185da8e573926 100644 (file)
@@ -57,7 +57,7 @@ class RepositoriesSubversionControllerTest < ActionController::TestCase
       assert_response :success
       assert_template 'show'
       assert_not_nil assigns(:entries)
-      assert_equal ['folder', '.project', 'helloworld.c', 'textfile.txt'], assigns(:entries).collect(&:name)
+      assert_equal ['[folder_with_brackets]', 'folder', '.project', 'helloworld.c', 'textfile.txt'], assigns(:entries).collect(&:name)
       entry = assigns(:entries).detect {|e| e.name == 'helloworld.c'}
       assert_equal 'file', entry.kind
       assert_equal 'subversion_test/helloworld.c', entry.path
index a2394facde0d5abf20ba68c03196a98423d3395f..ca4d2ce0430f35e14e27cb1616d445bf9973edcb 100644 (file)
@@ -18,7 +18,7 @@
 require File.dirname(__FILE__) + '/../test_helper'
 
 class RepositorySubversionTest < ActiveSupport::TestCase
-  fixtures :projects
+  fixtures :projects, :repositories
   
   def setup
     @project = Project.find(1)
@@ -30,8 +30,8 @@ class RepositorySubversionTest < ActiveSupport::TestCase
       @repository.fetch_changesets
       @repository.reload
       
-      assert_equal 10, @repository.changesets.count
-      assert_equal 18, @repository.changes.count
+      assert_equal 11, @repository.changesets.count
+      assert_equal 20, @repository.changes.count
       assert_equal 'Initial import.', @repository.changesets.find_by_revision('1').comments
     end
     
@@ -43,7 +43,7 @@ class RepositorySubversionTest < ActiveSupport::TestCase
       assert_equal 5, @repository.changesets.count
       
       @repository.fetch_changesets
-      assert_equal 10, @repository.changesets.count
+      assert_equal 11, @repository.changesets.count
     end
     
     def test_latest_changesets
@@ -62,6 +62,32 @@ class RepositorySubversionTest < ActiveSupport::TestCase
       changesets = @repository.latest_changesets('subversion_test/folder', 8)
       assert_equal ["7", "6", "5", "2"], changesets.collect(&:revision)
     end
+
+    def test_directory_listing_with_square_brackets_in_path
+      @repository.fetch_changesets
+      @repository.reload
+      
+      entries = @repository.entries('subversion_test/[folder_with_brackets]')
+      assert_not_nil entries, 'Expect to find entries in folder_with_brackets'
+      assert_equal 1, entries.size, 'Expect one entry in folder_with_brackets'
+      assert_equal 'README.txt', entries.first.name
+    end
+
+    def test_directory_listing_with_square_brackets_in_base
+      @project = Project.find(1)
+      @repository = Repository::Subversion.create(:project => @project, :url => "file:///#{self.class.repository_path('subversion')}/subversion_test/[folder_with_brackets]")
+
+      @repository.fetch_changesets
+      @repository.reload
+
+      assert_equal 1, @repository.changesets.count, 'Expected to see 1 revision'
+      assert_equal 2, @repository.changes.count, 'Expected to see 2 changes, dir add and file add'
+
+      entries = @repository.entries('')
+      assert_not_nil entries, 'Expect to find entries'
+      assert_equal 1, entries.size, 'Expect a single entry'
+      assert_equal 'README.txt', entries.first.name
+    end
   else
     puts "Subversion test repository NOT FOUND. Skipping unit tests !!!"
     def test_fake; assert true end