patch.diff

Gregor Schmidt, 2010-06-20 15:40

Download (39.2 KB)

View differences:

lib/redmine/scm/adapters/subversion_adapter.rb
47 47
        
48 48
        # Get info about the svn repository
49 49
        def info
50
          cmd = "#{SVN_BIN} info --xml #{target('')}"
50
          cmd = "#{SVN_BIN} info --xml #{target}"
51 51
          cmd << credentials_string
52 52
          info = nil
53 53
          shellout(cmd) do |io|
......
77 77
          path ||= ''
78 78
          identifier = (identifier and identifier.to_i > 0) ? identifier.to_i : "HEAD"
79 79
          entries = Entries.new
80
          cmd = "#{SVN_BIN} list --xml #{target(URI.escape(path))}@#{identifier}"
80
          cmd = "#{SVN_BIN} list --xml #{target(path)}@#{identifier}"
81 81
          cmd << credentials_string
82 82
          shellout(cmd) do |io|
83 83
            output = io.read
......
116 116
          return nil unless self.class.client_version_above?([1, 5, 0])
117 117
          
118 118
          identifier = (identifier and identifier.to_i > 0) ? identifier.to_i : "HEAD"
119
          cmd = "#{SVN_BIN} proplist --verbose --xml #{target(URI.escape(path))}@#{identifier}"
119
          cmd = "#{SVN_BIN} proplist --verbose --xml #{target(path)}@#{identifier}"
120 120
          cmd << credentials_string
121 121
          properties = {}
122 122
          shellout(cmd) do |io|
......
142 142
          cmd << credentials_string
143 143
          cmd << " --verbose " if  options[:with_paths]
144 144
          cmd << " --limit #{options[:limit].to_i}" if options[:limit]
145
          cmd << ' ' + target(URI.escape(path))
145
          cmd << ' ' + target(path)
146 146
          shellout(cmd) do |io|
147 147
            output = io.read
148 148
            begin
......
180 180
          cmd = "#{SVN_BIN} diff -r "
181 181
          cmd << "#{identifier_to}:"
182 182
          cmd << "#{identifier_from}"
183
          cmd << " #{target(URI.escape(path))}@#{identifier_from}"
183
          cmd << " #{target(path)}@#{identifier_from}"
184 184
          cmd << credentials_string
185 185
          diff = []
186 186
          shellout(cmd) do |io|
......
194 194
        
195 195
        def cat(path, identifier=nil)
196 196
          identifier = (identifier and identifier.to_i > 0) ? identifier.to_i : "HEAD"
197
          cmd = "#{SVN_BIN} cat #{target(URI.escape(path))}@#{identifier}"
197
          cmd = "#{SVN_BIN} cat #{target(path)}@#{identifier}"
198 198
          cmd << credentials_string
199 199
          cat = nil
200 200
          shellout(cmd) do |io|
......
207 207
        
208 208
        def annotate(path, identifier=nil)
209 209
          identifier = (identifier and identifier.to_i > 0) ? identifier.to_i : "HEAD"
210
          cmd = "#{SVN_BIN} blame #{target(URI.escape(path))}@#{identifier}"
210
          cmd = "#{SVN_BIN} blame #{target(path)}@#{identifier}"
211 211
          cmd << credentials_string
212 212
          blame = Annotate.new
213 213
          shellout(cmd) do |io|
......
243 243
            end
244 244
          end
245 245
        end
246

  
247
        def target(path = '')
248
          base = path.match(/^\//) ? root_url : url
249
          uri = "#{base}/#{path}"
250
          uri = URI.escape(URI.escape(uri), '[]')
251
          shell_quote(uri.gsub(/[?<>\*]/, ''))
252
        end
246 253
      end
247 254
    end
248 255
  end
test/functional/repositories_subversion_controller_test.rb
57 57
      assert_response :success
58 58
      assert_template 'show'
59 59
      assert_not_nil assigns(:entries)
60
      assert_equal ['folder', '.project', 'helloworld.c', 'textfile.txt'], assigns(:entries).collect(&:name)
60
      assert_equal ['[folder_with_brackets]', 'folder', '.project', 'helloworld.c', 'textfile.txt'], assigns(:entries).collect(&:name)
61 61
      entry = assigns(:entries).detect {|e| e.name == 'helloworld.c'}
62 62
      assert_equal 'file', entry.kind
63 63
      assert_equal 'subversion_test/helloworld.c', entry.path
test/unit/repository_subversion_test.rb
18 18
require File.dirname(__FILE__) + '/../test_helper'
19 19

  
20 20
class RepositorySubversionTest < ActiveSupport::TestCase
21
  fixtures :projects
21
  fixtures :projects, :repositories
22 22
  
23 23
  def setup
24 24
    @project = Project.find(1)
......
30 30
      @repository.fetch_changesets
31 31
      @repository.reload
32 32
      
33
      assert_equal 10, @repository.changesets.count
34
      assert_equal 18, @repository.changes.count
33
      assert_equal 11, @repository.changesets.count
34
      assert_equal 20, @repository.changes.count
35 35
      assert_equal 'Initial import.', @repository.changesets.find_by_revision('1').comments
36 36
    end
37 37
    
......
43 43
      assert_equal 5, @repository.changesets.count
44 44
      
45 45
      @repository.fetch_changesets
46
      assert_equal 10, @repository.changesets.count
46
      assert_equal 11, @repository.changesets.count
47 47
    end
48 48
    
49 49
    def test_latest_changesets
......
62 62
      changesets = @repository.latest_changesets('subversion_test/folder', 8)
63 63
      assert_equal ["7", "6", "5", "2"], changesets.collect(&:revision)
64 64
    end
65

  
66
    def test_directory_listing_with_square_brackets_in_path
67
      @repository.fetch_changesets
68
      @repository.reload
69
      
70
      entries = @repository.entries('subversion_test/[folder_with_brackets]')
71
      assert_not_nil entries, 'Expect to find entries in folder_with_brackets'
72
      assert_equal 1, entries.size, 'Expect one entry in folder_with_brackets'
73
      assert_equal 'README.txt', entries.first.name
74
    end
75

  
76
    def test_directory_listing_with_square_brackets_in_base
77
      @project = Project.find(1)
78
      @repository = Repository::Subversion.create(:project => @project, :url => "file:///#{self.class.repository_path('subversion')}/subversion_test/[folder_with_brackets]")
79

  
80
      @repository.fetch_changesets
81
      @repository.reload
82

  
83
      assert_equal 1, @repository.changesets.count, 'Expected to see 1 revision'
84
      assert_equal 2, @repository.changes.count, 'Expected to see 2 changes, dir add and file add'
85

  
86
      entries = @repository.entries('')
87
      assert_not_nil entries, 'Expect to find entries'
88
      assert_equal 1, entries.size, 'Expect a single entry'
89
      assert_equal 'README.txt', entries.first.name
90
    end
65 91
  else
66 92
    puts "Subversion test repository NOT FOUND. Skipping unit tests !!!"
67 93
    def test_fake; assert true end