Skip to content

Commit

Permalink
Support listing directories in svn which include square brackets. #5548
Browse files Browse the repository at this point in the history
Contributed by Gregor Schmidt

git-svn-id: svn+ssh://rubyforge.org/var/svn/redmine/trunk@3800 e93f8b46-1217-0410-a6f0-8f06a7374b81
  • Loading branch information
edavis10 committed Jun 20, 2010
1 parent 70da33f commit c5863c0
Show file tree
Hide file tree
Showing 4 changed files with 45 additions and 12 deletions.
21 changes: 14 additions & 7 deletions lib/redmine/scm/adapters/subversion_adapter.rb
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ def svn_binary_version


# Get info about the svn repository # Get info about the svn repository
def info def info
cmd = "#{SVN_BIN} info --xml #{target('')}" cmd = "#{SVN_BIN} info --xml #{target}"
cmd << credentials_string cmd << credentials_string
info = nil info = nil
shellout(cmd) do |io| shellout(cmd) do |io|
Expand Down Expand Up @@ -77,7 +77,7 @@ def entries(path=nil, identifier=nil)
path ||= '' path ||= ''
identifier = (identifier and identifier.to_i > 0) ? identifier.to_i : "HEAD" identifier = (identifier and identifier.to_i > 0) ? identifier.to_i : "HEAD"
entries = Entries.new entries = Entries.new
cmd = "#{SVN_BIN} list --xml #{target(URI.escape(path))}@#{identifier}" cmd = "#{SVN_BIN} list --xml #{target(path)}@#{identifier}"
cmd << credentials_string cmd << credentials_string
shellout(cmd) do |io| shellout(cmd) do |io|
output = io.read output = io.read
Expand Down Expand Up @@ -116,7 +116,7 @@ def properties(path, identifier=nil)
return nil unless self.class.client_version_above?([1, 5, 0]) return nil unless self.class.client_version_above?([1, 5, 0])


identifier = (identifier and identifier.to_i > 0) ? identifier.to_i : "HEAD" identifier = (identifier and identifier.to_i > 0) ? identifier.to_i : "HEAD"
cmd = "#{SVN_BIN} proplist --verbose --xml #{target(URI.escape(path))}@#{identifier}" cmd = "#{SVN_BIN} proplist --verbose --xml #{target(path)}@#{identifier}"
cmd << credentials_string cmd << credentials_string
properties = {} properties = {}
shellout(cmd) do |io| shellout(cmd) do |io|
Expand All @@ -142,7 +142,7 @@ def revisions(path=nil, identifier_from=nil, identifier_to=nil, options={})
cmd << credentials_string cmd << credentials_string
cmd << " --verbose " if options[:with_paths] cmd << " --verbose " if options[:with_paths]
cmd << " --limit #{options[:limit].to_i}" if options[:limit] cmd << " --limit #{options[:limit].to_i}" if options[:limit]
cmd << ' ' + target(URI.escape(path)) cmd << ' ' + target(path)
shellout(cmd) do |io| shellout(cmd) do |io|
output = io.read output = io.read
begin begin
Expand Down Expand Up @@ -180,7 +180,7 @@ def diff(path, identifier_from, identifier_to=nil, type="inline")
cmd = "#{SVN_BIN} diff -r " cmd = "#{SVN_BIN} diff -r "
cmd << "#{identifier_to}:" cmd << "#{identifier_to}:"
cmd << "#{identifier_from}" cmd << "#{identifier_from}"
cmd << " #{target(URI.escape(path))}@#{identifier_from}" cmd << " #{target(path)}@#{identifier_from}"
cmd << credentials_string cmd << credentials_string
diff = [] diff = []
shellout(cmd) do |io| shellout(cmd) do |io|
Expand All @@ -194,7 +194,7 @@ def diff(path, identifier_from, identifier_to=nil, type="inline")


def cat(path, identifier=nil) def cat(path, identifier=nil)
identifier = (identifier and identifier.to_i > 0) ? identifier.to_i : "HEAD" identifier = (identifier and identifier.to_i > 0) ? identifier.to_i : "HEAD"
cmd = "#{SVN_BIN} cat #{target(URI.escape(path))}@#{identifier}" cmd = "#{SVN_BIN} cat #{target(path)}@#{identifier}"
cmd << credentials_string cmd << credentials_string
cat = nil cat = nil
shellout(cmd) do |io| shellout(cmd) do |io|
Expand All @@ -207,7 +207,7 @@ def cat(path, identifier=nil)


def annotate(path, identifier=nil) def annotate(path, identifier=nil)
identifier = (identifier and identifier.to_i > 0) ? identifier.to_i : "HEAD" identifier = (identifier and identifier.to_i > 0) ? identifier.to_i : "HEAD"
cmd = "#{SVN_BIN} blame #{target(URI.escape(path))}@#{identifier}" cmd = "#{SVN_BIN} blame #{target(path)}@#{identifier}"
cmd << credentials_string cmd << credentials_string
blame = Annotate.new blame = Annotate.new
shellout(cmd) do |io| shellout(cmd) do |io|
Expand Down Expand Up @@ -243,6 +243,13 @@ def each_xml_element(node, name)
end end
end end
end end

def target(path = '')
base = path.match(/^\//) ? root_url : url
uri = "#{base}/#{path}"
uri = URI.escape(URI.escape(uri), '[]')
shell_quote(uri.gsub(/[?<>\*]/, ''))
end
end end
end end
end end
Expand Down
Binary file modified test/fixtures/repositories/subversion_repository.dump.gz
Binary file not shown.
2 changes: 1 addition & 1 deletion test/functional/repositories_subversion_controller_test.rb
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ def test_browse_directory
assert_response :success assert_response :success
assert_template 'show' assert_template 'show'
assert_not_nil assigns(:entries) 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'} entry = assigns(:entries).detect {|e| e.name == 'helloworld.c'}
assert_equal 'file', entry.kind assert_equal 'file', entry.kind
assert_equal 'subversion_test/helloworld.c', entry.path assert_equal 'subversion_test/helloworld.c', entry.path
Expand Down
34 changes: 30 additions & 4 deletions test/unit/repository_subversion_test.rb
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
require File.dirname(__FILE__) + '/../test_helper' require File.dirname(__FILE__) + '/../test_helper'


class RepositorySubversionTest < ActiveSupport::TestCase class RepositorySubversionTest < ActiveSupport::TestCase
fixtures :projects fixtures :projects, :repositories


def setup def setup
@project = Project.find(1) @project = Project.find(1)
Expand All @@ -30,8 +30,8 @@ def test_fetch_changesets_from_scratch
@repository.fetch_changesets @repository.fetch_changesets
@repository.reload @repository.reload


assert_equal 10, @repository.changesets.count assert_equal 11, @repository.changesets.count
assert_equal 18, @repository.changes.count assert_equal 20, @repository.changes.count
assert_equal 'Initial import.', @repository.changesets.find_by_revision('1').comments assert_equal 'Initial import.', @repository.changesets.find_by_revision('1').comments
end end


Expand All @@ -43,7 +43,7 @@ def test_fetch_changesets_incremental
assert_equal 5, @repository.changesets.count assert_equal 5, @repository.changesets.count


@repository.fetch_changesets @repository.fetch_changesets
assert_equal 10, @repository.changesets.count assert_equal 11, @repository.changesets.count
end end


def test_latest_changesets def test_latest_changesets
Expand All @@ -62,6 +62,32 @@ def test_latest_changesets
changesets = @repository.latest_changesets('subversion_test/folder', 8) changesets = @repository.latest_changesets('subversion_test/folder', 8)
assert_equal ["7", "6", "5", "2"], changesets.collect(&:revision) assert_equal ["7", "6", "5", "2"], changesets.collect(&:revision)
end 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 else
puts "Subversion test repository NOT FOUND. Skipping unit tests !!!" puts "Subversion test repository NOT FOUND. Skipping unit tests !!!"
def test_fake; assert true end def test_fake; assert true end
Expand Down

0 comments on commit c5863c0

Please sign in to comment.