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