##// END OF EJS Templates
Fixed that Repository#entries returns an Array....
Jean-Philippe Lang -
r9621:9b60214b3a3e
parent child
Show More
@@ -1,389 +1,389
1 1 # Redmine - project management software
2 2 # Copyright (C) 2006-2012 Jean-Philippe Lang
3 3 #
4 4 # This program is free software; you can redistribute it and/or
5 5 # modify it under the terms of the GNU General Public License
6 6 # as published by the Free Software Foundation; either version 2
7 7 # of the License, or (at your option) any later version.
8 8 #
9 9 # This program is distributed in the hope that it will be useful,
10 10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
11 11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 12 # GNU General Public License for more details.
13 13 #
14 14 # You should have received a copy of the GNU General Public License
15 15 # along with this program; if not, write to the Free Software
16 16 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
17 17
18 18 require 'cgi'
19 19
20 20 module Redmine
21 21 module Scm
22 22 module Adapters
23 23 class CommandFailed < StandardError #:nodoc:
24 24 end
25 25
26 26 class AbstractAdapter #:nodoc:
27 27
28 28 # raised if scm command exited with error, e.g. unknown revision.
29 29 class ScmCommandAborted < CommandFailed; end
30 30
31 31 class << self
32 32 def client_command
33 33 ""
34 34 end
35 35
36 36 def shell_quote_command
37 37 if Redmine::Platform.mswin? && RUBY_PLATFORM == 'java'
38 38 client_command
39 39 else
40 40 shell_quote(client_command)
41 41 end
42 42 end
43 43
44 44 # Returns the version of the scm client
45 45 # Eg: [1, 5, 0] or [] if unknown
46 46 def client_version
47 47 []
48 48 end
49 49
50 50 # Returns the version string of the scm client
51 51 # Eg: '1.5.0' or 'Unknown version' if unknown
52 52 def client_version_string
53 53 v = client_version || 'Unknown version'
54 54 v.is_a?(Array) ? v.join('.') : v.to_s
55 55 end
56 56
57 57 # Returns true if the current client version is above
58 58 # or equals the given one
59 59 # If option is :unknown is set to true, it will return
60 60 # true if the client version is unknown
61 61 def client_version_above?(v, options={})
62 62 ((client_version <=> v) >= 0) || (client_version.empty? && options[:unknown])
63 63 end
64 64
65 65 def client_available
66 66 true
67 67 end
68 68
69 69 def shell_quote(str)
70 70 if Redmine::Platform.mswin?
71 71 '"' + str.gsub(/"/, '\\"') + '"'
72 72 else
73 73 "'" + str.gsub(/'/, "'\"'\"'") + "'"
74 74 end
75 75 end
76 76 end
77 77
78 78 def initialize(url, root_url=nil, login=nil, password=nil,
79 79 path_encoding=nil)
80 80 @url = url
81 81 @login = login if login && !login.empty?
82 82 @password = (password || "") if @login
83 83 @root_url = root_url.blank? ? retrieve_root_url : root_url
84 84 end
85 85
86 86 def adapter_name
87 87 'Abstract'
88 88 end
89 89
90 90 def supports_cat?
91 91 true
92 92 end
93 93
94 94 def supports_annotate?
95 95 respond_to?('annotate')
96 96 end
97 97
98 98 def root_url
99 99 @root_url
100 100 end
101 101
102 102 def url
103 103 @url
104 104 end
105 105
106 106 def path_encoding
107 107 nil
108 108 end
109 109
110 110 # get info about the svn repository
111 111 def info
112 112 return nil
113 113 end
114 114
115 115 # Returns the entry identified by path and revision identifier
116 116 # or nil if entry doesn't exist in the repository
117 117 def entry(path=nil, identifier=nil)
118 118 parts = path.to_s.split(%r{[\/\\]}).select {|n| !n.blank?}
119 119 search_path = parts[0..-2].join('/')
120 120 search_name = parts[-1]
121 121 if search_path.blank? && search_name.blank?
122 122 # Root entry
123 123 Entry.new(:path => '', :kind => 'dir')
124 124 else
125 125 # Search for the entry in the parent directory
126 126 es = entries(search_path, identifier)
127 127 es ? es.detect {|e| e.name == search_name} : nil
128 128 end
129 129 end
130 130
131 131 # Returns an Entries collection
132 132 # or nil if the given path doesn't exist in the repository
133 133 def entries(path=nil, identifier=nil, options={})
134 134 return nil
135 135 end
136 136
137 137 def branches
138 138 return nil
139 139 end
140 140
141 141 def tags
142 142 return nil
143 143 end
144 144
145 145 def default_branch
146 146 return nil
147 147 end
148 148
149 149 def properties(path, identifier=nil)
150 150 return nil
151 151 end
152 152
153 153 def revisions(path=nil, identifier_from=nil, identifier_to=nil, options={})
154 154 return nil
155 155 end
156 156
157 157 def diff(path, identifier_from, identifier_to=nil)
158 158 return nil
159 159 end
160 160
161 161 def cat(path, identifier=nil)
162 162 return nil
163 163 end
164 164
165 165 def with_leading_slash(path)
166 166 path ||= ''
167 167 (path[0,1]!="/") ? "/#{path}" : path
168 168 end
169 169
170 170 def with_trailling_slash(path)
171 171 path ||= ''
172 172 (path[-1,1] == "/") ? path : "#{path}/"
173 173 end
174 174
175 175 def without_leading_slash(path)
176 176 path ||= ''
177 177 path.gsub(%r{^/+}, '')
178 178 end
179 179
180 180 def without_trailling_slash(path)
181 181 path ||= ''
182 182 (path[-1,1] == "/") ? path[0..-2] : path
183 183 end
184 184
185 185 def shell_quote(str)
186 186 self.class.shell_quote(str)
187 187 end
188 188
189 189 private
190 190 def retrieve_root_url
191 191 info = self.info
192 192 info ? info.root_url : nil
193 193 end
194 194
195 195 def target(path, sq=true)
196 196 path ||= ''
197 197 base = path.match(/^\//) ? root_url : url
198 198 str = "#{base}/#{path}".gsub(/[?<>\*]/, '')
199 199 if sq
200 200 str = shell_quote(str)
201 201 end
202 202 str
203 203 end
204 204
205 205 def logger
206 206 self.class.logger
207 207 end
208 208
209 209 def shellout(cmd, options = {}, &block)
210 210 self.class.shellout(cmd, options, &block)
211 211 end
212 212
213 213 def self.logger
214 214 Rails.logger
215 215 end
216 216
217 217 def self.shellout(cmd, options = {}, &block)
218 218 if logger && logger.debug?
219 219 logger.debug "Shelling out: #{strip_credential(cmd)}"
220 220 end
221 221 if Rails.env == 'development'
222 222 # Capture stderr when running in dev environment
223 223 cmd = "#{cmd} 2>>#{shell_quote(Rails.root.join('log/scm.stderr.log').to_s)}"
224 224 end
225 225 begin
226 226 mode = "r+"
227 227 IO.popen(cmd, mode) do |io|
228 228 io.set_encoding("ASCII-8BIT") if io.respond_to?(:set_encoding)
229 229 io.close_write unless options[:write_stdin]
230 230 block.call(io) if block_given?
231 231 end
232 232 ## If scm command does not exist,
233 233 ## Linux JRuby 1.6.2 (ruby-1.8.7-p330) raises java.io.IOException
234 234 ## in production environment.
235 235 # rescue Errno::ENOENT => e
236 236 rescue Exception => e
237 237 msg = strip_credential(e.message)
238 238 # The command failed, log it and re-raise
239 239 logmsg = "SCM command failed, "
240 240 logmsg += "make sure that your SCM command (e.g. svn) is "
241 241 logmsg += "in PATH (#{ENV['PATH']})\n"
242 242 logmsg += "You can configure your scm commands in config/configuration.yml.\n"
243 243 logmsg += "#{strip_credential(cmd)}\n"
244 244 logmsg += "with: #{msg}"
245 245 logger.error(logmsg)
246 246 raise CommandFailed.new(msg)
247 247 end
248 248 end
249 249
250 250 # Hides username/password in a given command
251 251 def self.strip_credential(cmd)
252 252 q = (Redmine::Platform.mswin? ? '"' : "'")
253 253 cmd.to_s.gsub(/(\-\-(password|username))\s+(#{q}[^#{q}]+#{q}|[^#{q}]\S+)/, '\\1 xxxx')
254 254 end
255 255
256 256 def strip_credential(cmd)
257 257 self.class.strip_credential(cmd)
258 258 end
259 259
260 260 def scm_iconv(to, from, str)
261 261 return nil if str.nil?
262 262 return str if to == from
263 263 begin
264 264 Iconv.conv(to, from, str)
265 265 rescue Iconv::Failure => err
266 266 logger.error("failed to convert from #{from} to #{to}. #{err}")
267 267 nil
268 268 end
269 269 end
270 270
271 271 def parse_xml(xml)
272 272 if RUBY_PLATFORM == 'java'
273 273 xml = xml.sub(%r{<\?xml[^>]*\?>}, '')
274 274 end
275 275 ActiveSupport::XmlMini.parse(xml)
276 276 end
277 277 end
278 278
279 279 class Entries < Array
280 280 def sort_by_name
281 sort {|x,y|
281 dup.sort! {|x,y|
282 282 if x.kind == y.kind
283 283 x.name.to_s <=> y.name.to_s
284 284 else
285 285 x.kind <=> y.kind
286 286 end
287 287 }
288 288 end
289 289
290 290 def revisions
291 291 revisions ||= Revisions.new(collect{|entry| entry.lastrev}.compact)
292 292 end
293 293 end
294 294
295 295 class Info
296 296 attr_accessor :root_url, :lastrev
297 297 def initialize(attributes={})
298 298 self.root_url = attributes[:root_url] if attributes[:root_url]
299 299 self.lastrev = attributes[:lastrev]
300 300 end
301 301 end
302 302
303 303 class Entry
304 304 attr_accessor :name, :path, :kind, :size, :lastrev
305 305 def initialize(attributes={})
306 306 self.name = attributes[:name] if attributes[:name]
307 307 self.path = attributes[:path] if attributes[:path]
308 308 self.kind = attributes[:kind] if attributes[:kind]
309 309 self.size = attributes[:size].to_i if attributes[:size]
310 310 self.lastrev = attributes[:lastrev]
311 311 end
312 312
313 313 def is_file?
314 314 'file' == self.kind
315 315 end
316 316
317 317 def is_dir?
318 318 'dir' == self.kind
319 319 end
320 320
321 321 def is_text?
322 322 Redmine::MimeType.is_type?('text', name)
323 323 end
324 324 end
325 325
326 326 class Revisions < Array
327 327 def latest
328 328 sort {|x,y|
329 329 unless x.time.nil? or y.time.nil?
330 330 x.time <=> y.time
331 331 else
332 332 0
333 333 end
334 334 }.last
335 335 end
336 336 end
337 337
338 338 class Revision
339 339 attr_accessor :scmid, :name, :author, :time, :message,
340 340 :paths, :revision, :branch, :identifier,
341 341 :parents
342 342
343 343 def initialize(attributes={})
344 344 self.identifier = attributes[:identifier]
345 345 self.scmid = attributes[:scmid]
346 346 self.name = attributes[:name] || self.identifier
347 347 self.author = attributes[:author]
348 348 self.time = attributes[:time]
349 349 self.message = attributes[:message] || ""
350 350 self.paths = attributes[:paths]
351 351 self.revision = attributes[:revision]
352 352 self.branch = attributes[:branch]
353 353 self.parents = attributes[:parents]
354 354 end
355 355
356 356 # Returns the readable identifier.
357 357 def format_identifier
358 358 self.identifier.to_s
359 359 end
360 360 end
361 361
362 362 class Annotate
363 363 attr_reader :lines, :revisions
364 364
365 365 def initialize
366 366 @lines = []
367 367 @revisions = []
368 368 end
369 369
370 370 def add_line(line, revision)
371 371 @lines << line
372 372 @revisions << revision
373 373 end
374 374
375 375 def content
376 376 content = lines.join("\n")
377 377 end
378 378
379 379 def empty?
380 380 lines.empty?
381 381 end
382 382 end
383 383
384 384 class Branch < String
385 385 attr_accessor :revision, :scmid
386 386 end
387 387 end
388 388 end
389 389 end
@@ -1,147 +1,148
1 1 # Redmine - project management software
2 2 # Copyright (C) 2006-2012 Jean-Philippe Lang
3 3 #
4 4 # This program is free software; you can redistribute it and/or
5 5 # modify it under the terms of the GNU General Public License
6 6 # as published by the Free Software Foundation; either version 2
7 7 # of the License, or (at your option) any later version.
8 8 #
9 9 # This program is distributed in the hope that it will be useful,
10 10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
11 11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 12 # GNU General Public License for more details.
13 13 #
14 14 # You should have received a copy of the GNU General Public License
15 15 # along with this program; if not, write to the Free Software
16 16 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
17 17
18 18 require File.expand_path('../../test_helper', __FILE__)
19 19
20 20 class RepositoryBazaarTest < ActiveSupport::TestCase
21 21 fixtures :projects
22 22
23 23 include Redmine::I18n
24 24
25 25 REPOSITORY_PATH = Rails.root.join('tmp/test/bazaar_repository/trunk').to_s
26 26 REPOSITORY_PATH.gsub!(/\/+/, '/')
27 27 NUM_REV = 4
28 28
29 29 def setup
30 30 @project = Project.find(3)
31 31 @repository = Repository::Bazaar.create(
32 32 :project => @project, :url => "file:///#{REPOSITORY_PATH}",
33 33 :log_encoding => 'UTF-8')
34 34 assert @repository
35 35 end
36 36
37 37 def test_blank_path_to_repository_error_message
38 38 set_language_if_valid 'en'
39 39 repo = Repository::Bazaar.new(
40 40 :project => @project,
41 41 :identifier => 'test',
42 42 :log_encoding => 'UTF-8'
43 43 )
44 44 assert !repo.save
45 45 assert_include "Path to repository can't be blank",
46 46 repo.errors.full_messages
47 47 end
48 48
49 49 def test_blank_path_to_repository_error_message_fr
50 50 set_language_if_valid 'fr'
51 51 str = "Chemin du d\xc3\xa9p\xc3\xb4t doit \xc3\xaatre renseign\xc3\xa9(e)"
52 52 str.force_encoding('UTF-8') if str.respond_to?(:force_encoding)
53 53 repo = Repository::Bazaar.new(
54 54 :project => @project,
55 55 :url => "",
56 56 :identifier => 'test',
57 57 :log_encoding => 'UTF-8'
58 58 )
59 59 assert !repo.save
60 60 assert_include str, repo.errors.full_messages
61 61 end
62 62
63 63 if File.directory?(REPOSITORY_PATH)
64 64 def test_fetch_changesets_from_scratch
65 65 assert_equal 0, @repository.changesets.count
66 66 @repository.fetch_changesets
67 67 @project.reload
68 68
69 69 assert_equal NUM_REV, @repository.changesets.count
70 70 assert_equal 9, @repository.filechanges.count
71 71 assert_equal 'Initial import', @repository.changesets.find_by_revision('1').comments
72 72 end
73 73
74 74 def test_fetch_changesets_incremental
75 75 assert_equal 0, @repository.changesets.count
76 76 @repository.fetch_changesets
77 77 @project.reload
78 78 assert_equal NUM_REV, @repository.changesets.count
79 79 # Remove changesets with revision > 5
80 80 @repository.changesets.find(:all).each {|c| c.destroy if c.revision.to_i > 2}
81 81 @project.reload
82 82 assert_equal 2, @repository.changesets.count
83 83
84 84 @repository.fetch_changesets
85 85 @project.reload
86 86 assert_equal NUM_REV, @repository.changesets.count
87 87 end
88 88
89 89 def test_entries
90 90 entries = @repository.entries
91 assert_kind_of Redmine::Scm::Adapters::Entries, entries
91 92 assert_equal 2, entries.size
92 93
93 94 assert_equal 'dir', entries[0].kind
94 95 assert_equal 'directory', entries[0].name
95 96
96 97 assert_equal 'file', entries[1].kind
97 98 assert_equal 'doc-mkdir.txt', entries[1].name
98 99 end
99 100
100 101 def test_entries_in_subdirectory
101 102 entries = @repository.entries('directory')
102 103 assert_equal 3, entries.size
103 104
104 105 assert_equal 'file', entries.last.kind
105 106 assert_equal 'edit.png', entries.last.name
106 107 end
107 108
108 109 def test_previous
109 110 assert_equal 0, @repository.changesets.count
110 111 @repository.fetch_changesets
111 112 @project.reload
112 113 assert_equal NUM_REV, @repository.changesets.count
113 114 changeset = @repository.find_changeset_by_name('3')
114 115 assert_equal @repository.find_changeset_by_name('2'), changeset.previous
115 116 end
116 117
117 118 def test_previous_nil
118 119 assert_equal 0, @repository.changesets.count
119 120 @repository.fetch_changesets
120 121 @project.reload
121 122 assert_equal NUM_REV, @repository.changesets.count
122 123 changeset = @repository.find_changeset_by_name('1')
123 124 assert_nil changeset.previous
124 125 end
125 126
126 127 def test_next
127 128 assert_equal 0, @repository.changesets.count
128 129 @repository.fetch_changesets
129 130 @project.reload
130 131 assert_equal NUM_REV, @repository.changesets.count
131 132 changeset = @repository.find_changeset_by_name('2')
132 133 assert_equal @repository.find_changeset_by_name('3'), changeset.next
133 134 end
134 135
135 136 def test_next_nil
136 137 assert_equal 0, @repository.changesets.count
137 138 @repository.fetch_changesets
138 139 @project.reload
139 140 assert_equal NUM_REV, @repository.changesets.count
140 141 changeset = @repository.find_changeset_by_name('4')
141 142 assert_nil changeset.next
142 143 end
143 144 else
144 145 puts "Bazaar test repository NOT FOUND. Skipping unit tests !!!"
145 146 def test_fake; assert true end
146 147 end
147 148 end
@@ -1,240 +1,241
1 1 # Redmine - project management software
2 2 # Copyright (C) 2006-2012 Jean-Philippe Lang
3 3 #
4 4 # This program is free software; you can redistribute it and/or
5 5 # modify it under the terms of the GNU General Public License
6 6 # as published by the Free Software Foundation; either version 2
7 7 # of the License, or (at your option) any later version.
8 8 #
9 9 # This program is distributed in the hope that it will be useful,
10 10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
11 11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 12 # GNU General Public License for more details.
13 13 #
14 14 # You should have received a copy of the GNU General Public License
15 15 # along with this program; if not, write to the Free Software
16 16 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
17 17
18 18 require File.expand_path('../../test_helper', __FILE__)
19 19 require 'pp'
20 20 class RepositoryCvsTest < ActiveSupport::TestCase
21 21 fixtures :projects
22 22
23 23 include Redmine::I18n
24 24
25 25 REPOSITORY_PATH = Rails.root.join('tmp/test/cvs_repository').to_s
26 26 REPOSITORY_PATH.gsub!(/\//, "\\") if Redmine::Platform.mswin?
27 27 # CVS module
28 28 MODULE_NAME = 'test'
29 29 CHANGESETS_NUM = 7
30 30
31 31 def setup
32 32 @project = Project.find(3)
33 33 @repository = Repository::Cvs.create(:project => @project,
34 34 :root_url => REPOSITORY_PATH,
35 35 :url => MODULE_NAME,
36 36 :log_encoding => 'UTF-8')
37 37 assert @repository
38 38 end
39 39
40 40 def test_blank_module_error_message
41 41 set_language_if_valid 'en'
42 42 repo = Repository::Cvs.new(
43 43 :project => @project,
44 44 :identifier => 'test',
45 45 :log_encoding => 'UTF-8',
46 46 :root_url => REPOSITORY_PATH
47 47 )
48 48 assert !repo.save
49 49 assert_include "Module can't be blank",
50 50 repo.errors.full_messages
51 51 end
52 52
53 53 def test_blank_module_error_message_fr
54 54 set_language_if_valid 'fr'
55 55 str = "Module doit \xc3\xaatre renseign\xc3\xa9(e)"
56 56 str.force_encoding('UTF-8') if str.respond_to?(:force_encoding)
57 57 repo = Repository::Cvs.new(
58 58 :project => @project,
59 59 :identifier => 'test',
60 60 :log_encoding => 'UTF-8',
61 61 :path_encoding => '',
62 62 :url => '',
63 63 :root_url => REPOSITORY_PATH
64 64 )
65 65 assert !repo.save
66 66 assert_include str, repo.errors.full_messages
67 67 end
68 68
69 69 def test_blank_cvsroot_error_message
70 70 set_language_if_valid 'en'
71 71 repo = Repository::Cvs.new(
72 72 :project => @project,
73 73 :identifier => 'test',
74 74 :log_encoding => 'UTF-8',
75 75 :url => MODULE_NAME
76 76 )
77 77 assert !repo.save
78 78 assert_include "CVSROOT can't be blank",
79 79 repo.errors.full_messages
80 80 end
81 81
82 82 def test_blank_cvsroot_error_message_fr
83 83 set_language_if_valid 'fr'
84 84 str = "CVSROOT doit \xc3\xaatre renseign\xc3\xa9(e)"
85 85 str.force_encoding('UTF-8') if str.respond_to?(:force_encoding)
86 86 repo = Repository::Cvs.new(
87 87 :project => @project,
88 88 :identifier => 'test',
89 89 :log_encoding => 'UTF-8',
90 90 :path_encoding => '',
91 91 :url => MODULE_NAME,
92 92 :root_url => ''
93 93 )
94 94 assert !repo.save
95 95 assert_include str, repo.errors.full_messages
96 96 end
97 97
98 98 if File.directory?(REPOSITORY_PATH)
99 99 def test_fetch_changesets_from_scratch
100 100 assert_equal 0, @repository.changesets.count
101 101 @repository.fetch_changesets
102 102 @project.reload
103 103
104 104 assert_equal CHANGESETS_NUM, @repository.changesets.count
105 105 assert_equal 16, @repository.filechanges.count
106 106 assert_not_nil @repository.changesets.find_by_comments('Two files changed')
107 107
108 108 r2 = @repository.changesets.find_by_revision('2')
109 109 assert_equal 'v1-20071213-162510', r2.scmid
110 110 end
111 111
112 112 def test_fetch_changesets_incremental
113 113 assert_equal 0, @repository.changesets.count
114 114 @repository.fetch_changesets
115 115 @project.reload
116 116 assert_equal CHANGESETS_NUM, @repository.changesets.count
117 117
118 118 # Remove changesets with revision > 3
119 119 @repository.changesets.find(:all).each {|c| c.destroy if c.revision.to_i > 3}
120 120 @project.reload
121 121 assert_equal 3, @repository.changesets.count
122 122 assert_equal %w|3 2 1|, @repository.changesets.all.collect(&:revision)
123 123
124 124 rev3_commit = @repository.changesets.find(:first, :order => 'committed_on DESC')
125 125 assert_equal '3', rev3_commit.revision
126 126 # 2007-12-14 01:27:22 +0900
127 127 rev3_committed_on = Time.gm(2007, 12, 13, 16, 27, 22)
128 128 assert_equal 'HEAD-20071213-162722', rev3_commit.scmid
129 129 assert_equal rev3_committed_on, rev3_commit.committed_on
130 130 latest_rev = @repository.latest_changeset
131 131 assert_equal rev3_committed_on, latest_rev.committed_on
132 132
133 133 @repository.fetch_changesets
134 134 @project.reload
135 135 assert_equal CHANGESETS_NUM, @repository.changesets.count
136 136 assert_equal %w|7 6 5 4 3 2 1|, @repository.changesets.all.collect(&:revision)
137 137 rev5_commit = @repository.changesets.find_by_revision('5')
138 138 assert_equal 'HEAD-20071213-163001', rev5_commit.scmid
139 139 # 2007-12-14 01:30:01 +0900
140 140 rev5_committed_on = Time.gm(2007, 12, 13, 16, 30, 1)
141 141 assert_equal rev5_committed_on, rev5_commit.committed_on
142 142 end
143 143
144 144 def test_deleted_files_should_not_be_listed
145 145 assert_equal 0, @repository.changesets.count
146 146 @repository.fetch_changesets
147 147 @project.reload
148 148 assert_equal CHANGESETS_NUM, @repository.changesets.count
149 149
150 150 entries = @repository.entries('sources')
151 151 assert entries.detect {|e| e.name == 'watchers_controller.rb'}
152 152 assert_nil entries.detect {|e| e.name == 'welcome_controller.rb'}
153 153 end
154 154
155 155 def test_entries_rev3
156 156 assert_equal 0, @repository.changesets.count
157 157 @repository.fetch_changesets
158 158 @project.reload
159 159 assert_equal CHANGESETS_NUM, @repository.changesets.count
160 160 entries = @repository.entries('', '3')
161 assert_kind_of Redmine::Scm::Adapters::Entries, entries
161 162 assert_equal 3, entries.size
162 163 assert_equal entries[2].name, "README"
163 164 assert_equal entries[2].lastrev.time, Time.gm(2007, 12, 13, 16, 27, 22)
164 165 assert_equal entries[2].lastrev.identifier, '3'
165 166 assert_equal entries[2].lastrev.revision, '3'
166 167 assert_equal entries[2].lastrev.author, 'LANG'
167 168 end
168 169
169 170 def test_entries_invalid_path
170 171 assert_equal 0, @repository.changesets.count
171 172 @repository.fetch_changesets
172 173 @project.reload
173 174 assert_equal CHANGESETS_NUM, @repository.changesets.count
174 175 assert_nil @repository.entries('missing')
175 176 assert_nil @repository.entries('missing', '3')
176 177 end
177 178
178 179 def test_entries_invalid_revision
179 180 assert_equal 0, @repository.changesets.count
180 181 @repository.fetch_changesets
181 182 @project.reload
182 183 assert_equal CHANGESETS_NUM, @repository.changesets.count
183 184 assert_nil @repository.entries('', '123')
184 185 end
185 186
186 187 def test_cat
187 188 assert_equal 0, @repository.changesets.count
188 189 @repository.fetch_changesets
189 190 @project.reload
190 191 assert_equal CHANGESETS_NUM, @repository.changesets.count
191 192 buf = @repository.cat('README')
192 193 assert buf
193 194 lines = buf.split("\n")
194 195 assert_equal 3, lines.length
195 196 buf = lines[1].gsub(/\r$/, "")
196 197 assert_equal 'with one change', buf
197 198 buf = @repository.cat('README', '1')
198 199 assert buf
199 200 lines = buf.split("\n")
200 201 assert_equal 1, lines.length
201 202 buf = lines[0].gsub(/\r$/, "")
202 203 assert_equal 'CVS test repository', buf
203 204 assert_nil @repository.cat('missing.rb')
204 205
205 206 # sources/welcome_controller.rb is removed at revision 5.
206 207 assert @repository.cat('sources/welcome_controller.rb', '4')
207 208 assert @repository.cat('sources/welcome_controller.rb', '5').blank?
208 209
209 210 # invalid revision
210 211 assert @repository.cat('README', '123').blank?
211 212 end
212 213
213 214 def test_annotate
214 215 assert_equal 0, @repository.changesets.count
215 216 @repository.fetch_changesets
216 217 @project.reload
217 218 assert_equal CHANGESETS_NUM, @repository.changesets.count
218 219 ann = @repository.annotate('README')
219 220 assert ann
220 221 assert_equal 3, ann.revisions.length
221 222 assert_equal '1.2', ann.revisions[1].revision
222 223 assert_equal 'LANG', ann.revisions[1].author
223 224 assert_equal 'with one change', ann.lines[1]
224 225
225 226 ann = @repository.annotate('README', '1')
226 227 assert ann
227 228 assert_equal 1, ann.revisions.length
228 229 assert_equal '1.1', ann.revisions[0].revision
229 230 assert_equal 'LANG', ann.revisions[0].author
230 231 assert_equal 'CVS test repository', ann.lines[0]
231 232
232 233 # invalid revision
233 234 assert_nil @repository.annotate('README', '123')
234 235 end
235 236
236 237 else
237 238 puts "CVS test repository NOT FOUND. Skipping unit tests !!!"
238 239 def test_fake; assert true end
239 240 end
240 241 end
@@ -1,124 +1,129
1 1 # Redmine - project management software
2 2 # Copyright (C) 2006-2012 Jean-Philippe Lang
3 3 #
4 4 # This program is free software; you can redistribute it and/or
5 5 # modify it under the terms of the GNU General Public License
6 6 # as published by the Free Software Foundation; either version 2
7 7 # of the License, or (at your option) any later version.
8 8 #
9 9 # This program is distributed in the hope that it will be useful,
10 10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
11 11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 12 # GNU General Public License for more details.
13 13 #
14 14 # You should have received a copy of the GNU General Public License
15 15 # along with this program; if not, write to the Free Software
16 16 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
17 17
18 18 require File.expand_path('../../test_helper', __FILE__)
19 19
20 20 class RepositoryDarcsTest < ActiveSupport::TestCase
21 21 fixtures :projects
22 22
23 23 include Redmine::I18n
24 24
25 25 REPOSITORY_PATH = Rails.root.join('tmp/test/darcs_repository').to_s
26 26 NUM_REV = 6
27 27
28 28 def setup
29 29 @project = Project.find(3)
30 30 @repository = Repository::Darcs.create(
31 31 :project => @project,
32 32 :url => REPOSITORY_PATH,
33 33 :log_encoding => 'UTF-8'
34 34 )
35 35 assert @repository
36 36 end
37 37
38 38 def test_blank_path_to_repository_error_message
39 39 set_language_if_valid 'en'
40 40 repo = Repository::Darcs.new(
41 41 :project => @project,
42 42 :identifier => 'test',
43 43 :log_encoding => 'UTF-8'
44 44 )
45 45 assert !repo.save
46 46 assert_include "Path to repository can't be blank",
47 47 repo.errors.full_messages
48 48 end
49 49
50 50 def test_blank_path_to_repository_error_message_fr
51 51 set_language_if_valid 'fr'
52 52 str = "Chemin du d\xc3\xa9p\xc3\xb4t doit \xc3\xaatre renseign\xc3\xa9(e)"
53 53 str.force_encoding('UTF-8') if str.respond_to?(:force_encoding)
54 54 repo = Repository::Darcs.new(
55 55 :project => @project,
56 56 :url => "",
57 57 :identifier => 'test',
58 58 :log_encoding => 'UTF-8'
59 59 )
60 60 assert !repo.save
61 61 assert_include str, repo.errors.full_messages
62 62 end
63 63
64 64 if File.directory?(REPOSITORY_PATH)
65 65 def test_fetch_changesets_from_scratch
66 66 assert_equal 0, @repository.changesets.count
67 67 @repository.fetch_changesets
68 68 @project.reload
69 69
70 70 assert_equal NUM_REV, @repository.changesets.count
71 71 assert_equal 13, @repository.filechanges.count
72 72 assert_equal "Initial commit.", @repository.changesets.find_by_revision('1').comments
73 73 end
74 74
75 75 def test_fetch_changesets_incremental
76 76 assert_equal 0, @repository.changesets.count
77 77 @repository.fetch_changesets
78 78 @project.reload
79 79 assert_equal NUM_REV, @repository.changesets.count
80 80
81 81 # Remove changesets with revision > 3
82 82 @repository.changesets.find(:all).each {|c| c.destroy if c.revision.to_i > 3}
83 83 @project.reload
84 84 assert_equal 3, @repository.changesets.count
85 85
86 86 @repository.fetch_changesets
87 87 @project.reload
88 88 assert_equal NUM_REV, @repository.changesets.count
89 89 end
90 90
91 def test_entries
92 entries = @repository.entries
93 assert_kind_of Redmine::Scm::Adapters::Entries, entries
94 end
95
91 96 def test_entries_invalid_revision
92 97 assert_equal 0, @repository.changesets.count
93 98 @repository.fetch_changesets
94 99 @project.reload
95 100 assert_equal NUM_REV, @repository.changesets.count
96 101 assert_nil @repository.entries('', '123')
97 102 end
98 103
99 104 def test_deleted_files_should_not_be_listed
100 105 assert_equal 0, @repository.changesets.count
101 106 @repository.fetch_changesets
102 107 @project.reload
103 108 assert_equal NUM_REV, @repository.changesets.count
104 109 entries = @repository.entries('sources')
105 110 assert entries.detect {|e| e.name == 'watchers_controller.rb'}
106 111 assert_nil entries.detect {|e| e.name == 'welcome_controller.rb'}
107 112 end
108 113
109 114 def test_cat
110 115 if @repository.scm.supports_cat?
111 116 assert_equal 0, @repository.changesets.count
112 117 @repository.fetch_changesets
113 118 @project.reload
114 119 assert_equal NUM_REV, @repository.changesets.count
115 120 cat = @repository.cat("sources/welcome_controller.rb", 2)
116 121 assert_not_nil cat
117 122 assert cat.include?('class WelcomeController < ApplicationController')
118 123 end
119 124 end
120 125 else
121 126 puts "Darcs test repository NOT FOUND. Skipping unit tests !!!"
122 127 def test_fake; assert true end
123 128 end
124 129 end
@@ -1,84 +1,89
1 1 # Redmine - project management software
2 2 # Copyright (C) 2006-2012 Jean-Philippe Lang
3 3 #
4 4 # This program is free software; you can redistribute it and/or
5 5 # modify it under the terms of the GNU General Public License
6 6 # as published by the Free Software Foundation; either version 2
7 7 # of the License, or (at your option) any later version.
8 8 #
9 9 # This program is distributed in the hope that it will be useful,
10 10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
11 11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 12 # GNU General Public License for more details.
13 13 #
14 14 # You should have received a copy of the GNU General Public License
15 15 # along with this program; if not, write to the Free Software
16 16 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
17 17
18 18 require File.expand_path('../../test_helper', __FILE__)
19 19
20 20 class RepositoryFilesystemTest < ActiveSupport::TestCase
21 21 fixtures :projects
22 22
23 23 include Redmine::I18n
24 24
25 25 REPOSITORY_PATH = Rails.root.join('tmp/test/filesystem_repository').to_s
26 26
27 27 def setup
28 28 @project = Project.find(3)
29 29 Setting.enabled_scm << 'Filesystem' unless Setting.enabled_scm.include?('Filesystem')
30 30 @repository = Repository::Filesystem.create(
31 31 :project => @project,
32 32 :url => REPOSITORY_PATH
33 33 )
34 34 assert @repository
35 35 end
36 36
37 37 def test_blank_root_directory_error_message
38 38 set_language_if_valid 'en'
39 39 repo = Repository::Filesystem.new(
40 40 :project => @project,
41 41 :identifier => 'test'
42 42 )
43 43 assert !repo.save
44 44 assert_include "Root directory can't be blank",
45 45 repo.errors.full_messages
46 46 end
47 47
48 48 def test_blank_root_directory_error_message_fr
49 49 set_language_if_valid 'fr'
50 50 str = "R\xc3\xa9pertoire racine doit \xc3\xaatre renseign\xc3\xa9(e)"
51 51 str.force_encoding('UTF-8') if str.respond_to?(:force_encoding)
52 52 repo = Repository::Filesystem.new(
53 53 :project => @project,
54 54 :url => "",
55 55 :identifier => 'test',
56 56 :path_encoding => ''
57 57 )
58 58 assert !repo.save
59 59 assert_include str, repo.errors.full_messages
60 60 end
61 61
62 62 if File.directory?(REPOSITORY_PATH)
63 63 def test_fetch_changesets
64 64 assert_equal 0, @repository.changesets.count
65 65 assert_equal 0, @repository.filechanges.count
66 66 @repository.fetch_changesets
67 67 @project.reload
68 68 assert_equal 0, @repository.changesets.count
69 69 assert_equal 0, @repository.filechanges.count
70 70 end
71 71
72 72 def test_entries
73 assert_equal 3, @repository.entries("", 2).size
73 entries = @repository.entries("", 2)
74 assert_kind_of Redmine::Scm::Adapters::Entries, entries
75 assert_equal 3, entries.size
76 end
77
78 def test_entries_in_directory
74 79 assert_equal 2, @repository.entries("dir", 3).size
75 80 end
76 81
77 82 def test_cat
78 83 assert_equal "TEST CAT\n", @repository.scm.cat("test")
79 84 end
80 85 else
81 86 puts "Filesystem test repository NOT FOUND. Skipping unit tests !!! See doc/RUNNING_TESTS."
82 87 def test_fake; assert true end
83 88 end
84 89 end
@@ -1,562 +1,567
1 1 # Redmine - project management software
2 2 # Copyright (C) 2006-2012 Jean-Philippe Lang
3 3 #
4 4 # This program is free software; you can redistribute it and/or
5 5 # modify it under the terms of the GNU General Public License
6 6 # as published by the Free Software Foundation; either version 2
7 7 # of the License, or (at your option) any later version.
8 8 #
9 9 # This program is distributed in the hope that it will be useful,
10 10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
11 11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 12 # GNU General Public License for more details.
13 13 #
14 14 # You should have received a copy of the GNU General Public License
15 15 # along with this program; if not, write to the Free Software
16 16 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
17 17
18 18 require File.expand_path('../../test_helper', __FILE__)
19 19
20 20 class RepositoryGitTest < ActiveSupport::TestCase
21 21 fixtures :projects, :repositories, :enabled_modules, :users, :roles
22 22
23 23 include Redmine::I18n
24 24
25 25 REPOSITORY_PATH = Rails.root.join('tmp/test/git_repository').to_s
26 26 REPOSITORY_PATH.gsub!(/\//, "\\") if Redmine::Platform.mswin?
27 27
28 28 NUM_REV = 28
29 29 NUM_HEAD = 6
30 30
31 31 FELIX_HEX = "Felix Sch\xC3\xA4fer"
32 32 CHAR_1_HEX = "\xc3\x9c"
33 33
34 34 ## Ruby uses ANSI api to fork a process on Windows.
35 35 ## Japanese Shift_JIS and Traditional Chinese Big5 have 0x5c(backslash) problem
36 36 ## and these are incompatible with ASCII.
37 37 ## Git for Windows (msysGit) changed internal API from ANSI to Unicode in 1.7.10
38 38 ## http://code.google.com/p/msysgit/issues/detail?id=80
39 39 ## So, Latin-1 path tests fail on Japanese Windows
40 40 WINDOWS_PASS = (Redmine::Platform.mswin? &&
41 41 Redmine::Scm::Adapters::GitAdapter.client_version_above?([1, 7, 10]))
42 42 WINDOWS_SKIP_STR = "TODO: This test fails in Git for Windows above 1.7.10"
43 43
44 44 ## Git, Mercurial and CVS path encodings are binary.
45 45 ## Subversion supports URL encoding for path.
46 46 ## Redmine Mercurial adapter and extension use URL encoding.
47 47 ## Git accepts only binary path in command line parameter.
48 48 ## So, there is no way to use binary command line parameter in JRuby.
49 49 JRUBY_SKIP = (RUBY_PLATFORM == 'java')
50 50 JRUBY_SKIP_STR = "TODO: This test fails in JRuby"
51 51
52 52 def setup
53 53 @project = Project.find(3)
54 54 @repository = Repository::Git.create(
55 55 :project => @project,
56 56 :url => REPOSITORY_PATH,
57 57 :path_encoding => 'ISO-8859-1'
58 58 )
59 59 assert @repository
60 60 @char_1 = CHAR_1_HEX.dup
61 61 if @char_1.respond_to?(:force_encoding)
62 62 @char_1.force_encoding('UTF-8')
63 63 end
64 64 end
65 65
66 66 def test_blank_path_to_repository_error_message
67 67 set_language_if_valid 'en'
68 68 repo = Repository::Git.new(
69 69 :project => @project,
70 70 :identifier => 'test'
71 71 )
72 72 assert !repo.save
73 73 assert_include "Path to repository can't be blank",
74 74 repo.errors.full_messages
75 75 end
76 76
77 77 def test_blank_path_to_repository_error_message_fr
78 78 set_language_if_valid 'fr'
79 79 str = "Chemin du d\xc3\xa9p\xc3\xb4t doit \xc3\xaatre renseign\xc3\xa9(e)"
80 80 str.force_encoding('UTF-8') if str.respond_to?(:force_encoding)
81 81 repo = Repository::Git.new(
82 82 :project => @project,
83 83 :url => "",
84 84 :identifier => 'test',
85 85 :path_encoding => ''
86 86 )
87 87 assert !repo.save
88 88 assert_include str, repo.errors.full_messages
89 89 end
90 90
91 91 if File.directory?(REPOSITORY_PATH)
92 92 def test_scm_available
93 93 klass = Repository::Git
94 94 assert_equal "Git", klass.scm_name
95 95 assert klass.scm_adapter_class
96 96 assert_not_equal "", klass.scm_command
97 97 assert_equal true, klass.scm_available
98 98 end
99 99
100 def test_entries
101 entries = @repository.entries
102 assert_kind_of Redmine::Scm::Adapters::Entries, entries
103 end
104
100 105 def test_fetch_changesets_from_scratch
101 106 assert_nil @repository.extra_info
102 107
103 108 assert_equal 0, @repository.changesets.count
104 109 @repository.fetch_changesets
105 110 @project.reload
106 111
107 112 assert_equal NUM_REV, @repository.changesets.count
108 113 assert_equal 39, @repository.filechanges.count
109 114
110 115 commit = @repository.changesets.find_by_revision("7234cb2750b63f47bff735edc50a1c0a433c2518")
111 116 assert_equal "7234cb2750b63f47bff735edc50a1c0a433c2518", commit.scmid
112 117 assert_equal "Initial import.\nThe repository contains 3 files.", commit.comments
113 118 assert_equal "jsmith <jsmith@foo.bar>", commit.committer
114 119 assert_equal User.find_by_login('jsmith'), commit.user
115 120 # TODO: add a commit with commit time <> author time to the test repository
116 121 assert_equal "2007-12-14 09:22:52".to_time, commit.committed_on
117 122 assert_equal "2007-12-14".to_date, commit.commit_date
118 123 assert_equal 3, commit.filechanges.count
119 124 change = commit.filechanges.sort_by(&:path).first
120 125 assert_equal "README", change.path
121 126 assert_equal nil, change.from_path
122 127 assert_equal "A", change.action
123 128
124 129 assert_equal NUM_HEAD, @repository.extra_info["heads"].size
125 130 end
126 131
127 132 def test_fetch_changesets_incremental
128 133 assert_equal 0, @repository.changesets.count
129 134 @repository.fetch_changesets
130 135 @project.reload
131 136 assert_equal NUM_REV, @repository.changesets.count
132 137 extra_info_heads = @repository.extra_info["heads"].dup
133 138 assert_equal NUM_HEAD, extra_info_heads.size
134 139 extra_info_heads.delete_if { |x| x == "83ca5fd546063a3c7dc2e568ba3355661a9e2b2c" }
135 140 assert_equal 4, extra_info_heads.size
136 141
137 142 del_revs = [
138 143 "83ca5fd546063a3c7dc2e568ba3355661a9e2b2c",
139 144 "ed5bb786bbda2dee66a2d50faf51429dbc043a7b",
140 145 "4f26664364207fa8b1af9f8722647ab2d4ac5d43",
141 146 "deff712f05a90d96edbd70facc47d944be5897e3",
142 147 "32ae898b720c2f7eec2723d5bdd558b4cb2d3ddf",
143 148 "7e61ac704deecde634b51e59daa8110435dcb3da",
144 149 ]
145 150 @repository.changesets.each do |rev|
146 151 rev.destroy if del_revs.detect {|r| r == rev.scmid.to_s }
147 152 end
148 153 @project.reload
149 154 cs1 = @repository.changesets
150 155 assert_equal NUM_REV - 6, cs1.count
151 156 extra_info_heads << "4a07fe31bffcf2888791f3e6cbc9c4545cefe3e8"
152 157 h = {}
153 158 h["heads"] = extra_info_heads
154 159 @repository.merge_extra_info(h)
155 160 @repository.save
156 161 @project.reload
157 162 assert @repository.extra_info["heads"].index("4a07fe31bffcf2888791f3e6cbc9c4545cefe3e8")
158 163 @repository.fetch_changesets
159 164 @project.reload
160 165 assert_equal NUM_REV, @repository.changesets.count
161 166 assert_equal NUM_HEAD, @repository.extra_info["heads"].size
162 167 assert @repository.extra_info["heads"].index("83ca5fd546063a3c7dc2e568ba3355661a9e2b2c")
163 168 end
164 169
165 170 def test_fetch_changesets_history_editing
166 171 assert_equal 0, @repository.changesets.count
167 172 @repository.fetch_changesets
168 173 @project.reload
169 174 assert_equal NUM_REV, @repository.changesets.count
170 175 extra_info_heads = @repository.extra_info["heads"].dup
171 176 assert_equal NUM_HEAD, extra_info_heads.size
172 177 extra_info_heads.delete_if { |x| x == "83ca5fd546063a3c7dc2e568ba3355661a9e2b2c" }
173 178 assert_equal 4, extra_info_heads.size
174 179
175 180 del_revs = [
176 181 "83ca5fd546063a3c7dc2e568ba3355661a9e2b2c",
177 182 "ed5bb786bbda2dee66a2d50faf51429dbc043a7b",
178 183 "4f26664364207fa8b1af9f8722647ab2d4ac5d43",
179 184 "deff712f05a90d96edbd70facc47d944be5897e3",
180 185 "32ae898b720c2f7eec2723d5bdd558b4cb2d3ddf",
181 186 "7e61ac704deecde634b51e59daa8110435dcb3da",
182 187 ]
183 188 @repository.changesets.each do |rev|
184 189 rev.destroy if del_revs.detect {|r| r == rev.scmid.to_s }
185 190 end
186 191 @project.reload
187 192 assert_equal NUM_REV - 6, @repository.changesets.count
188 193
189 194 c = Changeset.new(:repository => @repository,
190 195 :committed_on => Time.now,
191 196 :revision => "abcd1234efgh",
192 197 :scmid => "abcd1234efgh",
193 198 :comments => 'test')
194 199 assert c.save
195 200 @project.reload
196 201 assert_equal NUM_REV - 5, @repository.changesets.count
197 202
198 203 extra_info_heads << "1234abcd5678"
199 204 h = {}
200 205 h["heads"] = extra_info_heads
201 206 @repository.merge_extra_info(h)
202 207 @repository.save
203 208 @project.reload
204 209 h1 = @repository.extra_info["heads"].dup
205 210 assert h1.index("1234abcd5678")
206 211 assert_equal 5, h1.size
207 212
208 213 @repository.fetch_changesets
209 214 @project.reload
210 215 assert_equal NUM_REV - 5, @repository.changesets.count
211 216 h2 = @repository.extra_info["heads"].dup
212 217 assert_equal h1, h2
213 218 end
214 219
215 220 def test_parents
216 221 assert_equal 0, @repository.changesets.count
217 222 @repository.fetch_changesets
218 223 @project.reload
219 224 assert_equal NUM_REV, @repository.changesets.count
220 225 r1 = @repository.find_changeset_by_name("7234cb2750b63")
221 226 assert_equal [], r1.parents
222 227 r2 = @repository.find_changeset_by_name("899a15dba03a3")
223 228 assert_equal 1, r2.parents.length
224 229 assert_equal "7234cb2750b63f47bff735edc50a1c0a433c2518",
225 230 r2.parents[0].identifier
226 231 r3 = @repository.find_changeset_by_name("32ae898b720c2")
227 232 assert_equal 2, r3.parents.length
228 233 r4 = [r3.parents[0].identifier, r3.parents[1].identifier].sort
229 234 assert_equal "4a07fe31bffcf2888791f3e6cbc9c4545cefe3e8", r4[0]
230 235 assert_equal "7e61ac704deecde634b51e59daa8110435dcb3da", r4[1]
231 236 end
232 237
233 238 def test_db_consistent_ordering_init
234 239 assert_nil @repository.extra_info
235 240 assert_equal 0, @repository.changesets.count
236 241 @repository.fetch_changesets
237 242 @project.reload
238 243 assert_equal 1, @repository.extra_info["db_consistent"]["ordering"]
239 244 end
240 245
241 246 def test_db_consistent_ordering_before_1_2
242 247 assert_nil @repository.extra_info
243 248 assert_equal 0, @repository.changesets.count
244 249 @repository.fetch_changesets
245 250 @project.reload
246 251 assert_equal NUM_REV, @repository.changesets.count
247 252 assert_not_nil @repository.extra_info
248 253 h = {}
249 254 h["heads"] = []
250 255 h["branches"] = {}
251 256 h["db_consistent"] = {}
252 257 @repository.merge_extra_info(h)
253 258 @repository.save
254 259 assert_equal NUM_REV, @repository.changesets.count
255 260 @repository.fetch_changesets
256 261 @project.reload
257 262 assert_equal 0, @repository.extra_info["db_consistent"]["ordering"]
258 263
259 264 extra_info_heads = @repository.extra_info["heads"].dup
260 265 extra_info_heads.delete_if { |x| x == "83ca5fd546063a3c7dc2e568ba3355661a9e2b2c" }
261 266 del_revs = [
262 267 "83ca5fd546063a3c7dc2e568ba3355661a9e2b2c",
263 268 "ed5bb786bbda2dee66a2d50faf51429dbc043a7b",
264 269 "4f26664364207fa8b1af9f8722647ab2d4ac5d43",
265 270 "deff712f05a90d96edbd70facc47d944be5897e3",
266 271 "32ae898b720c2f7eec2723d5bdd558b4cb2d3ddf",
267 272 "7e61ac704deecde634b51e59daa8110435dcb3da",
268 273 ]
269 274 @repository.changesets.each do |rev|
270 275 rev.destroy if del_revs.detect {|r| r == rev.scmid.to_s }
271 276 end
272 277 @project.reload
273 278 cs1 = @repository.changesets
274 279 assert_equal NUM_REV - 6, cs1.count
275 280 assert_equal 0, @repository.extra_info["db_consistent"]["ordering"]
276 281
277 282 extra_info_heads << "4a07fe31bffcf2888791f3e6cbc9c4545cefe3e8"
278 283 h = {}
279 284 h["heads"] = extra_info_heads
280 285 @repository.merge_extra_info(h)
281 286 @repository.save
282 287 @project.reload
283 288 assert @repository.extra_info["heads"].index("4a07fe31bffcf2888791f3e6cbc9c4545cefe3e8")
284 289 @repository.fetch_changesets
285 290 @project.reload
286 291 assert_equal NUM_REV, @repository.changesets.count
287 292 assert_equal NUM_HEAD, @repository.extra_info["heads"].size
288 293
289 294 assert_equal 0, @repository.extra_info["db_consistent"]["ordering"]
290 295 end
291 296
292 297 def test_heads_from_branches_hash
293 298 assert_nil @repository.extra_info
294 299 assert_equal 0, @repository.changesets.count
295 300 assert_equal [], @repository.heads_from_branches_hash
296 301 h = {}
297 302 h["branches"] = {}
298 303 h["branches"]["test1"] = {}
299 304 h["branches"]["test1"]["last_scmid"] = "1234abcd"
300 305 h["branches"]["test2"] = {}
301 306 h["branches"]["test2"]["last_scmid"] = "abcd1234"
302 307 @repository.merge_extra_info(h)
303 308 @repository.save
304 309 @project.reload
305 310 assert_equal ["1234abcd", "abcd1234"], @repository.heads_from_branches_hash.sort
306 311 end
307 312
308 313 def test_latest_changesets
309 314 assert_equal 0, @repository.changesets.count
310 315 @repository.fetch_changesets
311 316 @project.reload
312 317 assert_equal NUM_REV, @repository.changesets.count
313 318 # with limit
314 319 changesets = @repository.latest_changesets('', 'master', 2)
315 320 assert_equal 2, changesets.size
316 321
317 322 # with path
318 323 changesets = @repository.latest_changesets('images', 'master')
319 324 assert_equal [
320 325 'deff712f05a90d96edbd70facc47d944be5897e3',
321 326 '899a15dba03a3b350b89c3f537e4bbe02a03cdc9',
322 327 '7234cb2750b63f47bff735edc50a1c0a433c2518',
323 328 ], changesets.collect(&:revision)
324 329
325 330 changesets = @repository.latest_changesets('README', nil)
326 331 assert_equal [
327 332 '32ae898b720c2f7eec2723d5bdd558b4cb2d3ddf',
328 333 '4a07fe31bffcf2888791f3e6cbc9c4545cefe3e8',
329 334 '713f4944648826f558cf548222f813dabe7cbb04',
330 335 '61b685fbe55ab05b5ac68402d5720c1a6ac973d1',
331 336 '899a15dba03a3b350b89c3f537e4bbe02a03cdc9',
332 337 '7234cb2750b63f47bff735edc50a1c0a433c2518',
333 338 ], changesets.collect(&:revision)
334 339
335 340 # with path, revision and limit
336 341 changesets = @repository.latest_changesets('images', '899a15dba')
337 342 assert_equal [
338 343 '899a15dba03a3b350b89c3f537e4bbe02a03cdc9',
339 344 '7234cb2750b63f47bff735edc50a1c0a433c2518',
340 345 ], changesets.collect(&:revision)
341 346
342 347 changesets = @repository.latest_changesets('images', '899a15dba', 1)
343 348 assert_equal [
344 349 '899a15dba03a3b350b89c3f537e4bbe02a03cdc9',
345 350 ], changesets.collect(&:revision)
346 351
347 352 changesets = @repository.latest_changesets('README', '899a15dba')
348 353 assert_equal [
349 354 '899a15dba03a3b350b89c3f537e4bbe02a03cdc9',
350 355 '7234cb2750b63f47bff735edc50a1c0a433c2518',
351 356 ], changesets.collect(&:revision)
352 357
353 358 changesets = @repository.latest_changesets('README', '899a15dba', 1)
354 359 assert_equal [
355 360 '899a15dba03a3b350b89c3f537e4bbe02a03cdc9',
356 361 ], changesets.collect(&:revision)
357 362
358 363 # with path, tag and limit
359 364 changesets = @repository.latest_changesets('images', 'tag01.annotated')
360 365 assert_equal [
361 366 '899a15dba03a3b350b89c3f537e4bbe02a03cdc9',
362 367 '7234cb2750b63f47bff735edc50a1c0a433c2518',
363 368 ], changesets.collect(&:revision)
364 369
365 370 changesets = @repository.latest_changesets('images', 'tag01.annotated', 1)
366 371 assert_equal [
367 372 '899a15dba03a3b350b89c3f537e4bbe02a03cdc9',
368 373 ], changesets.collect(&:revision)
369 374
370 375 changesets = @repository.latest_changesets('README', 'tag01.annotated')
371 376 assert_equal [
372 377 '899a15dba03a3b350b89c3f537e4bbe02a03cdc9',
373 378 '7234cb2750b63f47bff735edc50a1c0a433c2518',
374 379 ], changesets.collect(&:revision)
375 380
376 381 changesets = @repository.latest_changesets('README', 'tag01.annotated', 1)
377 382 assert_equal [
378 383 '899a15dba03a3b350b89c3f537e4bbe02a03cdc9',
379 384 ], changesets.collect(&:revision)
380 385
381 386 # with path, branch and limit
382 387 changesets = @repository.latest_changesets('images', 'test_branch')
383 388 assert_equal [
384 389 '899a15dba03a3b350b89c3f537e4bbe02a03cdc9',
385 390 '7234cb2750b63f47bff735edc50a1c0a433c2518',
386 391 ], changesets.collect(&:revision)
387 392
388 393 changesets = @repository.latest_changesets('images', 'test_branch', 1)
389 394 assert_equal [
390 395 '899a15dba03a3b350b89c3f537e4bbe02a03cdc9',
391 396 ], changesets.collect(&:revision)
392 397
393 398 changesets = @repository.latest_changesets('README', 'test_branch')
394 399 assert_equal [
395 400 '713f4944648826f558cf548222f813dabe7cbb04',
396 401 '61b685fbe55ab05b5ac68402d5720c1a6ac973d1',
397 402 '899a15dba03a3b350b89c3f537e4bbe02a03cdc9',
398 403 '7234cb2750b63f47bff735edc50a1c0a433c2518',
399 404 ], changesets.collect(&:revision)
400 405
401 406 changesets = @repository.latest_changesets('README', 'test_branch', 2)
402 407 assert_equal [
403 408 '713f4944648826f558cf548222f813dabe7cbb04',
404 409 '61b685fbe55ab05b5ac68402d5720c1a6ac973d1',
405 410 ], changesets.collect(&:revision)
406 411
407 412 if WINDOWS_PASS
408 413 puts WINDOWS_SKIP_STR
409 414 elsif JRUBY_SKIP
410 415 puts JRUBY_SKIP_STR
411 416 else
412 417 # latin-1 encoding path
413 418 changesets = @repository.latest_changesets(
414 419 "latin-1-dir/test-#{@char_1}-2.txt", '64f1f3e89')
415 420 assert_equal [
416 421 '64f1f3e89ad1cb57976ff0ad99a107012ba3481d',
417 422 '4fc55c43bf3d3dc2efb66145365ddc17639ce81e',
418 423 ], changesets.collect(&:revision)
419 424
420 425 changesets = @repository.latest_changesets(
421 426 "latin-1-dir/test-#{@char_1}-2.txt", '64f1f3e89', 1)
422 427 assert_equal [
423 428 '64f1f3e89ad1cb57976ff0ad99a107012ba3481d',
424 429 ], changesets.collect(&:revision)
425 430 end
426 431 end
427 432
428 433 def test_latest_changesets_latin_1_dir
429 434 if WINDOWS_PASS
430 435 puts WINDOWS_SKIP_STR
431 436 elsif JRUBY_SKIP
432 437 puts JRUBY_SKIP_STR
433 438 else
434 439 assert_equal 0, @repository.changesets.count
435 440 @repository.fetch_changesets
436 441 @project.reload
437 442 assert_equal NUM_REV, @repository.changesets.count
438 443 changesets = @repository.latest_changesets(
439 444 "latin-1-dir/test-#{@char_1}-subdir", '1ca7f5ed')
440 445 assert_equal [
441 446 '1ca7f5ed374f3cb31a93ae5215c2e25cc6ec5127',
442 447 ], changesets.collect(&:revision)
443 448 end
444 449 end
445 450
446 451 def test_find_changeset_by_name
447 452 assert_equal 0, @repository.changesets.count
448 453 @repository.fetch_changesets
449 454 @project.reload
450 455 assert_equal NUM_REV, @repository.changesets.count
451 456 ['7234cb2750b63f47bff735edc50a1c0a433c2518', '7234cb2750b'].each do |r|
452 457 assert_equal '7234cb2750b63f47bff735edc50a1c0a433c2518',
453 458 @repository.find_changeset_by_name(r).revision
454 459 end
455 460 end
456 461
457 462 def test_find_changeset_by_empty_name
458 463 assert_equal 0, @repository.changesets.count
459 464 @repository.fetch_changesets
460 465 @project.reload
461 466 assert_equal NUM_REV, @repository.changesets.count
462 467 ['', ' ', nil].each do |r|
463 468 assert_nil @repository.find_changeset_by_name(r)
464 469 end
465 470 end
466 471
467 472 def test_identifier
468 473 assert_equal 0, @repository.changesets.count
469 474 @repository.fetch_changesets
470 475 @project.reload
471 476 assert_equal NUM_REV, @repository.changesets.count
472 477 c = @repository.changesets.find_by_revision(
473 478 '7234cb2750b63f47bff735edc50a1c0a433c2518')
474 479 assert_equal c.scmid, c.identifier
475 480 end
476 481
477 482 def test_format_identifier
478 483 assert_equal 0, @repository.changesets.count
479 484 @repository.fetch_changesets
480 485 @project.reload
481 486 assert_equal NUM_REV, @repository.changesets.count
482 487 c = @repository.changesets.find_by_revision(
483 488 '7234cb2750b63f47bff735edc50a1c0a433c2518')
484 489 assert_equal '7234cb27', c.format_identifier
485 490 end
486 491
487 492 def test_activities
488 493 c = Changeset.new(:repository => @repository,
489 494 :committed_on => Time.now,
490 495 :revision => 'abc7234cb2750b63f47bff735edc50a1c0a433c2',
491 496 :scmid => 'abc7234cb2750b63f47bff735edc50a1c0a433c2',
492 497 :comments => 'test')
493 498 assert c.event_title.include?('abc7234c:')
494 499 assert_equal 'abc7234cb2750b63f47bff735edc50a1c0a433c2', c.event_url[:rev]
495 500 end
496 501
497 502 def test_log_utf8
498 503 assert_equal 0, @repository.changesets.count
499 504 @repository.fetch_changesets
500 505 @project.reload
501 506 assert_equal NUM_REV, @repository.changesets.count
502 507 str_felix_hex = FELIX_HEX.dup
503 508 if str_felix_hex.respond_to?(:force_encoding)
504 509 str_felix_hex.force_encoding('UTF-8')
505 510 end
506 511 c = @repository.changesets.find_by_revision(
507 512 'ed5bb786bbda2dee66a2d50faf51429dbc043a7b')
508 513 assert_equal "#{str_felix_hex} <felix@fachschaften.org>", c.committer
509 514 end
510 515
511 516 def test_previous
512 517 assert_equal 0, @repository.changesets.count
513 518 @repository.fetch_changesets
514 519 @project.reload
515 520 assert_equal NUM_REV, @repository.changesets.count
516 521 %w|1ca7f5ed374f3cb31a93ae5215c2e25cc6ec5127 1ca7f5ed|.each do |r1|
517 522 changeset = @repository.find_changeset_by_name(r1)
518 523 %w|64f1f3e89ad1cb57976ff0ad99a107012ba3481d 64f1f3e89ad1|.each do |r2|
519 524 assert_equal @repository.find_changeset_by_name(r2), changeset.previous
520 525 end
521 526 end
522 527 end
523 528
524 529 def test_previous_nil
525 530 assert_equal 0, @repository.changesets.count
526 531 @repository.fetch_changesets
527 532 @project.reload
528 533 assert_equal NUM_REV, @repository.changesets.count
529 534 %w|7234cb2750b63f47bff735edc50a1c0a433c2518 7234cb275|.each do |r1|
530 535 changeset = @repository.find_changeset_by_name(r1)
531 536 assert_nil changeset.previous
532 537 end
533 538 end
534 539
535 540 def test_next
536 541 assert_equal 0, @repository.changesets.count
537 542 @repository.fetch_changesets
538 543 @project.reload
539 544 assert_equal NUM_REV, @repository.changesets.count
540 545 %w|64f1f3e89ad1cb57976ff0ad99a107012ba3481d 64f1f3e89ad1|.each do |r2|
541 546 changeset = @repository.find_changeset_by_name(r2)
542 547 %w|1ca7f5ed374f3cb31a93ae5215c2e25cc6ec5127 1ca7f5ed|.each do |r1|
543 548 assert_equal @repository.find_changeset_by_name(r1), changeset.next
544 549 end
545 550 end
546 551 end
547 552
548 553 def test_next_nil
549 554 assert_equal 0, @repository.changesets.count
550 555 @repository.fetch_changesets
551 556 @project.reload
552 557 assert_equal NUM_REV, @repository.changesets.count
553 558 %w|2a682156a3b6e77a8bf9cd4590e8db757f3c6c78 2a682156a3b6e77a|.each do |r1|
554 559 changeset = @repository.find_changeset_by_name(r1)
555 560 assert_nil changeset.next
556 561 end
557 562 end
558 563 else
559 564 puts "Git test repository NOT FOUND. Skipping unit tests !!!"
560 565 def test_fake; assert true end
561 566 end
562 567 end
@@ -1,372 +1,377
1 1 # Redmine - project management software
2 2 # Copyright (C) 2006-2012 Jean-Philippe Lang
3 3 #
4 4 # This program is free software; you can redistribute it and/or
5 5 # modify it under the terms of the GNU General Public License
6 6 # as published by the Free Software Foundation; either version 2
7 7 # of the License, or (at your option) any later version.
8 8 #
9 9 # This program is distributed in the hope that it will be useful,
10 10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
11 11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 12 # GNU General Public License for more details.
13 13 #
14 14 # You should have received a copy of the GNU General Public License
15 15 # along with this program; if not, write to the Free Software
16 16 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
17 17
18 18 require File.expand_path('../../test_helper', __FILE__)
19 19
20 20 class RepositoryMercurialTest < ActiveSupport::TestCase
21 21 fixtures :projects
22 22
23 23 include Redmine::I18n
24 24
25 25 REPOSITORY_PATH = Rails.root.join('tmp/test/mercurial_repository').to_s
26 26 NUM_REV = 32
27 27 CHAR_1_HEX = "\xc3\x9c"
28 28
29 29 def setup
30 30 @project = Project.find(3)
31 31 @repository = Repository::Mercurial.create(
32 32 :project => @project,
33 33 :url => REPOSITORY_PATH,
34 34 :path_encoding => 'ISO-8859-1'
35 35 )
36 36 assert @repository
37 37 @char_1 = CHAR_1_HEX.dup
38 38 @tag_char_1 = "tag-#{CHAR_1_HEX}-00"
39 39 @branch_char_0 = "branch-#{CHAR_1_HEX}-00"
40 40 @branch_char_1 = "branch-#{CHAR_1_HEX}-01"
41 41 if @char_1.respond_to?(:force_encoding)
42 42 @char_1.force_encoding('UTF-8')
43 43 @tag_char_1.force_encoding('UTF-8')
44 44 @branch_char_0.force_encoding('UTF-8')
45 45 @branch_char_1.force_encoding('UTF-8')
46 46 end
47 47 end
48 48
49 49
50 50 def test_blank_path_to_repository_error_message
51 51 set_language_if_valid 'en'
52 52 repo = Repository::Mercurial.new(
53 53 :project => @project,
54 54 :identifier => 'test'
55 55 )
56 56 assert !repo.save
57 57 assert_include "Path to repository can't be blank",
58 58 repo.errors.full_messages
59 59 end
60 60
61 61 def test_blank_path_to_repository_error_message_fr
62 62 set_language_if_valid 'fr'
63 63 str = "Chemin du d\xc3\xa9p\xc3\xb4t doit \xc3\xaatre renseign\xc3\xa9(e)"
64 64 str.force_encoding('UTF-8') if str.respond_to?(:force_encoding)
65 65 repo = Repository::Mercurial.new(
66 66 :project => @project,
67 67 :url => "",
68 68 :identifier => 'test',
69 69 :path_encoding => ''
70 70 )
71 71 assert !repo.save
72 72 assert_include str, repo.errors.full_messages
73 73 end
74 74
75 75 if File.directory?(REPOSITORY_PATH)
76 76 def test_scm_available
77 77 klass = Repository::Mercurial
78 78 assert_equal "Mercurial", klass.scm_name
79 79 assert klass.scm_adapter_class
80 80 assert_not_equal "", klass.scm_command
81 81 assert_equal true, klass.scm_available
82 82 end
83 83
84 def test_entries
85 entries = @repository.entries
86 assert_kind_of Redmine::Scm::Adapters::Entries, entries
87 end
88
84 89 def test_fetch_changesets_from_scratch
85 90 assert_equal 0, @repository.changesets.count
86 91 @repository.fetch_changesets
87 92 @project.reload
88 93 assert_equal NUM_REV, @repository.changesets.count
89 94 assert_equal 46, @repository.filechanges.count
90 95 assert_equal "Initial import.\nThe repository contains 3 files.",
91 96 @repository.changesets.find_by_revision('0').comments
92 97 end
93 98
94 99 def test_fetch_changesets_incremental
95 100 assert_equal 0, @repository.changesets.count
96 101 @repository.fetch_changesets
97 102 @project.reload
98 103 assert_equal NUM_REV, @repository.changesets.count
99 104 # Remove changesets with revision > 2
100 105 @repository.changesets.find(:all).each {|c| c.destroy if c.revision.to_i > 2}
101 106 @project.reload
102 107 assert_equal 3, @repository.changesets.count
103 108
104 109 @repository.fetch_changesets
105 110 @project.reload
106 111 assert_equal NUM_REV, @repository.changesets.count
107 112 end
108 113
109 114 def test_isodatesec
110 115 # Template keyword 'isodatesec' supported in Mercurial 1.0 and higher
111 116 if @repository.scm.class.client_version_above?([1, 0])
112 117 assert_equal 0, @repository.changesets.count
113 118 @repository.fetch_changesets
114 119 @project.reload
115 120 assert_equal NUM_REV, @repository.changesets.count
116 121 rev0_committed_on = Time.gm(2007, 12, 14, 9, 22, 52)
117 122 assert_equal @repository.changesets.find_by_revision('0').committed_on, rev0_committed_on
118 123 end
119 124 end
120 125
121 126 def test_changeset_order_by_revision
122 127 assert_equal 0, @repository.changesets.count
123 128 @repository.fetch_changesets
124 129 @project.reload
125 130 assert_equal NUM_REV, @repository.changesets.count
126 131
127 132 c0 = @repository.latest_changeset
128 133 c1 = @repository.changesets.find_by_revision('0')
129 134 # sorted by revision (id), not by date
130 135 assert c0.revision.to_i > c1.revision.to_i
131 136 assert c0.committed_on < c1.committed_on
132 137 end
133 138
134 139 def test_latest_changesets
135 140 assert_equal 0, @repository.changesets.count
136 141 @repository.fetch_changesets
137 142 @project.reload
138 143 assert_equal NUM_REV, @repository.changesets.count
139 144
140 145 # with_limit
141 146 changesets = @repository.latest_changesets('', nil, 2)
142 147 assert_equal %w|31 30|, changesets.collect(&:revision)
143 148
144 149 # with_filepath
145 150 changesets = @repository.latest_changesets(
146 151 '/sql_escape/percent%dir/percent%file1.txt', nil)
147 152 assert_equal %w|30 11 10 9|, changesets.collect(&:revision)
148 153
149 154 changesets = @repository.latest_changesets(
150 155 '/sql_escape/underscore_dir/understrike_file.txt', nil)
151 156 assert_equal %w|30 12 9|, changesets.collect(&:revision)
152 157
153 158 changesets = @repository.latest_changesets('README', nil)
154 159 assert_equal %w|31 30 28 17 8 6 1 0|, changesets.collect(&:revision)
155 160
156 161 changesets = @repository.latest_changesets('README','8')
157 162 assert_equal %w|8 6 1 0|, changesets.collect(&:revision)
158 163
159 164 changesets = @repository.latest_changesets('README','8', 2)
160 165 assert_equal %w|8 6|, changesets.collect(&:revision)
161 166
162 167 # with_dirpath
163 168 changesets = @repository.latest_changesets('images', nil)
164 169 assert_equal %w|1 0|, changesets.collect(&:revision)
165 170
166 171 path = 'sql_escape/percent%dir'
167 172 changesets = @repository.latest_changesets(path, nil)
168 173 assert_equal %w|30 13 11 10 9|, changesets.collect(&:revision)
169 174
170 175 changesets = @repository.latest_changesets(path, '11')
171 176 assert_equal %w|11 10 9|, changesets.collect(&:revision)
172 177
173 178 changesets = @repository.latest_changesets(path, '11', 2)
174 179 assert_equal %w|11 10|, changesets.collect(&:revision)
175 180
176 181 path = 'sql_escape/underscore_dir'
177 182 changesets = @repository.latest_changesets(path, nil)
178 183 assert_equal %w|30 13 12 9|, changesets.collect(&:revision)
179 184
180 185 changesets = @repository.latest_changesets(path, '12')
181 186 assert_equal %w|12 9|, changesets.collect(&:revision)
182 187
183 188 changesets = @repository.latest_changesets(path, '12', 1)
184 189 assert_equal %w|12|, changesets.collect(&:revision)
185 190
186 191 # tag
187 192 changesets = @repository.latest_changesets('', 'tag_test.00')
188 193 assert_equal %w|5 4 3 2 1 0|, changesets.collect(&:revision)
189 194
190 195 changesets = @repository.latest_changesets('', 'tag_test.00', 2)
191 196 assert_equal %w|5 4|, changesets.collect(&:revision)
192 197
193 198 changesets = @repository.latest_changesets('sources', 'tag_test.00')
194 199 assert_equal %w|4 3 2 1 0|, changesets.collect(&:revision)
195 200
196 201 changesets = @repository.latest_changesets('sources', 'tag_test.00', 2)
197 202 assert_equal %w|4 3|, changesets.collect(&:revision)
198 203
199 204 # named branch
200 205 if @repository.scm.class.client_version_above?([1, 6])
201 206 changesets = @repository.latest_changesets('', @branch_char_1)
202 207 assert_equal %w|27 26|, changesets.collect(&:revision)
203 208 end
204 209
205 210 changesets = @repository.latest_changesets("latin-1-dir/test-#{@char_1}-subdir", @branch_char_1)
206 211 assert_equal %w|27|, changesets.collect(&:revision)
207 212 end
208 213
209 214 def test_copied_files
210 215 assert_equal 0, @repository.changesets.count
211 216 @repository.fetch_changesets
212 217 @project.reload
213 218 assert_equal NUM_REV, @repository.changesets.count
214 219
215 220 cs1 = @repository.changesets.find_by_revision('13')
216 221 assert_not_nil cs1
217 222 c1 = cs1.filechanges.sort_by(&:path)
218 223 assert_equal 2, c1.size
219 224
220 225 assert_equal 'A', c1[0].action
221 226 assert_equal '/sql_escape/percent%dir/percentfile1.txt', c1[0].path
222 227 assert_equal '/sql_escape/percent%dir/percent%file1.txt', c1[0].from_path
223 228 assert_equal '3a330eb32958', c1[0].from_revision
224 229
225 230 assert_equal 'A', c1[1].action
226 231 assert_equal '/sql_escape/underscore_dir/understrike-file.txt', c1[1].path
227 232 assert_equal '/sql_escape/underscore_dir/understrike_file.txt', c1[1].from_path
228 233
229 234 cs2 = @repository.changesets.find_by_revision('15')
230 235 c2 = cs2.filechanges
231 236 assert_equal 1, c2.size
232 237
233 238 assert_equal 'A', c2[0].action
234 239 assert_equal '/README (1)[2]&,%.-3_4', c2[0].path
235 240 assert_equal '/README', c2[0].from_path
236 241 assert_equal '933ca60293d7', c2[0].from_revision
237 242
238 243 cs3 = @repository.changesets.find_by_revision('19')
239 244 c3 = cs3.filechanges
240 245 assert_equal 1, c3.size
241 246 assert_equal 'A', c3[0].action
242 247 assert_equal "/latin-1-dir/test-#{@char_1}-1.txt", c3[0].path
243 248 assert_equal "/latin-1-dir/test-#{@char_1}.txt", c3[0].from_path
244 249 assert_equal '5d9891a1b425', c3[0].from_revision
245 250 end
246 251
247 252 def test_find_changeset_by_name
248 253 assert_equal 0, @repository.changesets.count
249 254 @repository.fetch_changesets
250 255 @project.reload
251 256 assert_equal NUM_REV, @repository.changesets.count
252 257 %w|2 400bb8672109 400|.each do |r|
253 258 assert_equal '2', @repository.find_changeset_by_name(r).revision
254 259 end
255 260 end
256 261
257 262 def test_find_changeset_by_invalid_name
258 263 assert_equal 0, @repository.changesets.count
259 264 @repository.fetch_changesets
260 265 @project.reload
261 266 assert_equal NUM_REV, @repository.changesets.count
262 267 assert_nil @repository.find_changeset_by_name('100000')
263 268 end
264 269
265 270 def test_identifier
266 271 assert_equal 0, @repository.changesets.count
267 272 @repository.fetch_changesets
268 273 @project.reload
269 274 assert_equal NUM_REV, @repository.changesets.count
270 275 c = @repository.changesets.find_by_revision('2')
271 276 assert_equal c.scmid, c.identifier
272 277 end
273 278
274 279 def test_format_identifier
275 280 assert_equal 0, @repository.changesets.count
276 281 @repository.fetch_changesets
277 282 @project.reload
278 283 assert_equal NUM_REV, @repository.changesets.count
279 284 c = @repository.changesets.find_by_revision('2')
280 285 assert_equal '2:400bb8672109', c.format_identifier
281 286 end
282 287
283 288 def test_find_changeset_by_empty_name
284 289 assert_equal 0, @repository.changesets.count
285 290 @repository.fetch_changesets
286 291 @project.reload
287 292 assert_equal NUM_REV, @repository.changesets.count
288 293 ['', ' ', nil].each do |r|
289 294 assert_nil @repository.find_changeset_by_name(r)
290 295 end
291 296 end
292 297
293 298 def test_parents
294 299 assert_equal 0, @repository.changesets.count
295 300 @repository.fetch_changesets
296 301 @project.reload
297 302 assert_equal NUM_REV, @repository.changesets.count
298 303 r1 = @repository.changesets.find_by_revision('0')
299 304 assert_equal [], r1.parents
300 305 r2 = @repository.changesets.find_by_revision('1')
301 306 assert_equal 1, r2.parents.length
302 307 assert_equal "0885933ad4f6",
303 308 r2.parents[0].identifier
304 309 r3 = @repository.changesets.find_by_revision('30')
305 310 assert_equal 2, r3.parents.length
306 311 r4 = [r3.parents[0].identifier, r3.parents[1].identifier].sort
307 312 assert_equal "3a330eb32958", r4[0]
308 313 assert_equal "a94b0528f24f", r4[1]
309 314 end
310 315
311 316 def test_activities
312 317 c = Changeset.new(:repository => @repository,
313 318 :committed_on => Time.now,
314 319 :revision => '123',
315 320 :scmid => 'abc400bb8672',
316 321 :comments => 'test')
317 322 assert c.event_title.include?('123:abc400bb8672:')
318 323 assert_equal 'abc400bb8672', c.event_url[:rev]
319 324 end
320 325
321 326 def test_previous
322 327 assert_equal 0, @repository.changesets.count
323 328 @repository.fetch_changesets
324 329 @project.reload
325 330 assert_equal NUM_REV, @repository.changesets.count
326 331 %w|28 3ae45e2d177d 3ae45|.each do |r1|
327 332 changeset = @repository.find_changeset_by_name(r1)
328 333 %w|27 7bbf4c738e71 7bbf|.each do |r2|
329 334 assert_equal @repository.find_changeset_by_name(r2), changeset.previous
330 335 end
331 336 end
332 337 end
333 338
334 339 def test_previous_nil
335 340 assert_equal 0, @repository.changesets.count
336 341 @repository.fetch_changesets
337 342 @project.reload
338 343 assert_equal NUM_REV, @repository.changesets.count
339 344 %w|0 0885933ad4f6 0885|.each do |r1|
340 345 changeset = @repository.find_changeset_by_name(r1)
341 346 assert_nil changeset.previous
342 347 end
343 348 end
344 349
345 350 def test_next
346 351 assert_equal 0, @repository.changesets.count
347 352 @repository.fetch_changesets
348 353 @project.reload
349 354 assert_equal NUM_REV, @repository.changesets.count
350 355 %w|27 7bbf4c738e71 7bbf|.each do |r2|
351 356 changeset = @repository.find_changeset_by_name(r2)
352 357 %w|28 3ae45e2d177d 3ae45|.each do |r1|
353 358 assert_equal @repository.find_changeset_by_name(r1), changeset.next
354 359 end
355 360 end
356 361 end
357 362
358 363 def test_next_nil
359 364 assert_equal 0, @repository.changesets.count
360 365 @repository.fetch_changesets
361 366 @project.reload
362 367 assert_equal NUM_REV, @repository.changesets.count
363 368 %w|31 31eeee7395c8 31eee|.each do |r1|
364 369 changeset = @repository.find_changeset_by_name(r1)
365 370 assert_nil changeset.next
366 371 end
367 372 end
368 373 else
369 374 puts "Mercurial test repository NOT FOUND. Skipping unit tests !!!"
370 375 def test_fake; assert true end
371 376 end
372 377 end
@@ -1,221 +1,226
1 1 # Redmine - project management software
2 2 # Copyright (C) 2006-2012 Jean-Philippe Lang
3 3 #
4 4 # This program is free software; you can redistribute it and/or
5 5 # modify it under the terms of the GNU General Public License
6 6 # as published by the Free Software Foundation; either version 2
7 7 # of the License, or (at your option) any later version.
8 8 #
9 9 # This program is distributed in the hope that it will be useful,
10 10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
11 11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 12 # GNU General Public License for more details.
13 13 #
14 14 # You should have received a copy of the GNU General Public License
15 15 # along with this program; if not, write to the Free Software
16 16 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
17 17
18 18 require File.expand_path('../../test_helper', __FILE__)
19 19
20 20 class RepositorySubversionTest < ActiveSupport::TestCase
21 21 fixtures :projects, :repositories, :enabled_modules, :users, :roles
22 22
23 23 NUM_REV = 11
24 24
25 25 def setup
26 26 @project = Project.find(3)
27 27 @repository = Repository::Subversion.create(:project => @project,
28 28 :url => self.class.subversion_repository_url)
29 29 assert @repository
30 30 end
31 31
32 32 if repository_configured?('subversion')
33 33 def test_fetch_changesets_from_scratch
34 34 assert_equal 0, @repository.changesets.count
35 35 @repository.fetch_changesets
36 36 @project.reload
37 37
38 38 assert_equal NUM_REV, @repository.changesets.count
39 39 assert_equal 20, @repository.filechanges.count
40 40 assert_equal 'Initial import.', @repository.changesets.find_by_revision('1').comments
41 41 end
42 42
43 43 def test_fetch_changesets_incremental
44 44 assert_equal 0, @repository.changesets.count
45 45 @repository.fetch_changesets
46 46 @project.reload
47 47 assert_equal NUM_REV, @repository.changesets.count
48 48
49 49 # Remove changesets with revision > 5
50 50 @repository.changesets.find(:all).each {|c| c.destroy if c.revision.to_i > 5}
51 51 @project.reload
52 52 assert_equal 5, @repository.changesets.count
53 53
54 54 @repository.fetch_changesets
55 55 @project.reload
56 56 assert_equal NUM_REV, @repository.changesets.count
57 57 end
58 58
59 def test_entries
60 entries = @repository.entries
61 assert_kind_of Redmine::Scm::Adapters::Entries, entries
62 end
63
59 64 def test_latest_changesets
60 65 assert_equal 0, @repository.changesets.count
61 66 @repository.fetch_changesets
62 67 @project.reload
63 68 assert_equal NUM_REV, @repository.changesets.count
64 69
65 70 # with limit
66 71 changesets = @repository.latest_changesets('', nil, 2)
67 72 assert_equal 2, changesets.size
68 73 assert_equal @repository.latest_changesets('', nil).slice(0,2), changesets
69 74
70 75 # with path
71 76 changesets = @repository.latest_changesets('subversion_test/folder', nil)
72 77 assert_equal ["10", "9", "7", "6", "5", "2"], changesets.collect(&:revision)
73 78
74 79 # with path and revision
75 80 changesets = @repository.latest_changesets('subversion_test/folder', 8)
76 81 assert_equal ["7", "6", "5", "2"], changesets.collect(&:revision)
77 82 end
78 83
79 84 def test_directory_listing_with_square_brackets_in_path
80 85 assert_equal 0, @repository.changesets.count
81 86 @repository.fetch_changesets
82 87 @project.reload
83 88 assert_equal NUM_REV, @repository.changesets.count
84 89
85 90 entries = @repository.entries('subversion_test/[folder_with_brackets]')
86 91 assert_not_nil entries, 'Expect to find entries in folder_with_brackets'
87 92 assert_equal 1, entries.size, 'Expect one entry in folder_with_brackets'
88 93 assert_equal 'README.txt', entries.first.name
89 94 end
90 95
91 96 def test_directory_listing_with_square_brackets_in_base
92 97 @project = Project.find(3)
93 98 @repository = Repository::Subversion.create(
94 99 :project => @project,
95 100 :url => "file:///#{self.class.repository_path('subversion')}/subversion_test/[folder_with_brackets]")
96 101
97 102 assert_equal 0, @repository.changesets.count
98 103 @repository.fetch_changesets
99 104 @project.reload
100 105
101 106 assert_equal 1, @repository.changesets.count, 'Expected to see 1 revision'
102 107 assert_equal 2, @repository.filechanges.count, 'Expected to see 2 changes, dir add and file add'
103 108
104 109 entries = @repository.entries('')
105 110 assert_not_nil entries, 'Expect to find entries'
106 111 assert_equal 1, entries.size, 'Expect a single entry'
107 112 assert_equal 'README.txt', entries.first.name
108 113 end
109 114
110 115 def test_identifier
111 116 assert_equal 0, @repository.changesets.count
112 117 @repository.fetch_changesets
113 118 @project.reload
114 119 assert_equal NUM_REV, @repository.changesets.count
115 120 c = @repository.changesets.find_by_revision('1')
116 121 assert_equal c.revision, c.identifier
117 122 end
118 123
119 124 def test_find_changeset_by_empty_name
120 125 assert_equal 0, @repository.changesets.count
121 126 @repository.fetch_changesets
122 127 @project.reload
123 128 assert_equal NUM_REV, @repository.changesets.count
124 129 ['', ' ', nil].each do |r|
125 130 assert_nil @repository.find_changeset_by_name(r)
126 131 end
127 132 end
128 133
129 134 def test_identifier_nine_digit
130 135 c = Changeset.new(:repository => @repository, :committed_on => Time.now,
131 136 :revision => '123456789', :comments => 'test')
132 137 assert_equal c.identifier, c.revision
133 138 end
134 139
135 140 def test_format_identifier
136 141 assert_equal 0, @repository.changesets.count
137 142 @repository.fetch_changesets
138 143 @project.reload
139 144 assert_equal NUM_REV, @repository.changesets.count
140 145 c = @repository.changesets.find_by_revision('1')
141 146 assert_equal c.format_identifier, c.revision
142 147 end
143 148
144 149 def test_format_identifier_nine_digit
145 150 c = Changeset.new(:repository => @repository, :committed_on => Time.now,
146 151 :revision => '123456789', :comments => 'test')
147 152 assert_equal c.format_identifier, c.revision
148 153 end
149 154
150 155 def test_activities
151 156 c = Changeset.new(:repository => @repository, :committed_on => Time.now,
152 157 :revision => '1', :comments => 'test')
153 158 assert c.event_title.include?('1:')
154 159 assert_equal '1', c.event_url[:rev]
155 160 end
156 161
157 162 def test_activities_nine_digit
158 163 c = Changeset.new(:repository => @repository, :committed_on => Time.now,
159 164 :revision => '123456789', :comments => 'test')
160 165 assert c.event_title.include?('123456789:')
161 166 assert_equal '123456789', c.event_url[:rev]
162 167 end
163 168
164 169 def test_log_encoding_ignore_setting
165 170 with_settings :commit_logs_encoding => 'windows-1252' do
166 171 s1 = "\xC2\x80"
167 172 s2 = "\xc3\x82\xc2\x80"
168 173 if s1.respond_to?(:force_encoding)
169 174 s1.force_encoding('ISO-8859-1')
170 175 s2.force_encoding('UTF-8')
171 176 assert_equal s1.encode('UTF-8'), s2
172 177 end
173 178 c = Changeset.new(:repository => @repository,
174 179 :comments => s2,
175 180 :revision => '123',
176 181 :committed_on => Time.now)
177 182 assert c.save
178 183 assert_equal s2, c.comments
179 184 end
180 185 end
181 186
182 187 def test_previous
183 188 assert_equal 0, @repository.changesets.count
184 189 @repository.fetch_changesets
185 190 @project.reload
186 191 assert_equal NUM_REV, @repository.changesets.count
187 192 changeset = @repository.find_changeset_by_name('3')
188 193 assert_equal @repository.find_changeset_by_name('2'), changeset.previous
189 194 end
190 195
191 196 def test_previous_nil
192 197 assert_equal 0, @repository.changesets.count
193 198 @repository.fetch_changesets
194 199 @project.reload
195 200 assert_equal NUM_REV, @repository.changesets.count
196 201 changeset = @repository.find_changeset_by_name('1')
197 202 assert_nil changeset.previous
198 203 end
199 204
200 205 def test_next
201 206 assert_equal 0, @repository.changesets.count
202 207 @repository.fetch_changesets
203 208 @project.reload
204 209 assert_equal NUM_REV, @repository.changesets.count
205 210 changeset = @repository.find_changeset_by_name('2')
206 211 assert_equal @repository.find_changeset_by_name('3'), changeset.next
207 212 end
208 213
209 214 def test_next_nil
210 215 assert_equal 0, @repository.changesets.count
211 216 @repository.fetch_changesets
212 217 @project.reload
213 218 assert_equal NUM_REV, @repository.changesets.count
214 219 changeset = @repository.find_changeset_by_name('11')
215 220 assert_nil changeset.next
216 221 end
217 222 else
218 223 puts "Subversion test repository NOT FOUND. Skipping unit tests !!!"
219 224 def test_fake; assert true end
220 225 end
221 226 end
General Comments 0
You need to be logged in to leave comments. Login now