@@ -1,420 +1,420 | |||
|
1 | 1 | # Redmine - project management software |
|
2 | 2 | # Copyright (C) 2006-2012 Jean-Philippe Lang |
|
3 | 3 | # |
|
4 | 4 | # This program is free software; you can redistribute it and/or |
|
5 | 5 | # modify it under the terms of the GNU General Public License |
|
6 | 6 | # as published by the Free Software Foundation; either version 2 |
|
7 | 7 | # of the License, or (at your option) any later version. |
|
8 | 8 | # |
|
9 | 9 | # This program is distributed in the hope that it will be useful, |
|
10 | 10 | # but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
11 | 11 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
12 | 12 | # GNU General Public License for more details. |
|
13 | 13 | # |
|
14 | 14 | # You should have received a copy of the GNU General Public License |
|
15 | 15 | # along with this program; if not, write to the Free Software |
|
16 | 16 | # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. |
|
17 | 17 | |
|
18 | 18 | require 'cgi' |
|
19 | 19 | |
|
20 | 20 | module Redmine |
|
21 | 21 | module Scm |
|
22 | 22 | module Adapters |
|
23 | 23 | class CommandFailed < StandardError #:nodoc: |
|
24 | 24 | end |
|
25 | 25 | |
|
26 | 26 | class AbstractAdapter #:nodoc: |
|
27 | 27 | |
|
28 | 28 | # raised if scm command exited with error, e.g. unknown revision. |
|
29 | 29 | class ScmCommandAborted < CommandFailed; end |
|
30 | 30 | |
|
31 | 31 | class << self |
|
32 | 32 | def client_command |
|
33 | 33 | "" |
|
34 | 34 | end |
|
35 | 35 | |
|
36 | 36 | def shell_quote_command |
|
37 | 37 | if Redmine::Platform.mswin? && RUBY_PLATFORM == 'java' |
|
38 | 38 | client_command |
|
39 | 39 | else |
|
40 | 40 | shell_quote(client_command) |
|
41 | 41 | end |
|
42 | 42 | end |
|
43 | 43 | |
|
44 | 44 | # Returns the version of the scm client |
|
45 | 45 | # Eg: [1, 5, 0] or [] if unknown |
|
46 | 46 | def client_version |
|
47 | 47 | [] |
|
48 | 48 | end |
|
49 | 49 | |
|
50 | 50 | # Returns the version string of the scm client |
|
51 | 51 | # Eg: '1.5.0' or 'Unknown version' if unknown |
|
52 | 52 | def client_version_string |
|
53 | 53 | v = client_version || 'Unknown version' |
|
54 | 54 | v.is_a?(Array) ? v.join('.') : v.to_s |
|
55 | 55 | end |
|
56 | 56 | |
|
57 | 57 | # Returns true if the current client version is above |
|
58 | 58 | # or equals the given one |
|
59 | 59 | # If option is :unknown is set to true, it will return |
|
60 | 60 | # true if the client version is unknown |
|
61 | 61 | def client_version_above?(v, options={}) |
|
62 | 62 | ((client_version <=> v) >= 0) || (client_version.empty? && options[:unknown]) |
|
63 | 63 | end |
|
64 | 64 | |
|
65 | 65 | def client_available |
|
66 | 66 | true |
|
67 | 67 | end |
|
68 | 68 | |
|
69 | 69 | def shell_quote(str) |
|
70 | 70 | if Redmine::Platform.mswin? |
|
71 | 71 | '"' + str.gsub(/"/, '\\"') + '"' |
|
72 | 72 | else |
|
73 | 73 | "'" + str.gsub(/'/, "'\"'\"'") + "'" |
|
74 | 74 | end |
|
75 | 75 | end |
|
76 | 76 | end |
|
77 | 77 | |
|
78 | 78 | def initialize(url, root_url=nil, login=nil, password=nil, |
|
79 | 79 | path_encoding=nil) |
|
80 | 80 | @url = url |
|
81 | 81 | @login = login if login && !login.empty? |
|
82 | 82 | @password = (password || "") if @login |
|
83 | 83 | @root_url = root_url.blank? ? retrieve_root_url : root_url |
|
84 | 84 | end |
|
85 | 85 | |
|
86 | 86 | def adapter_name |
|
87 | 87 | 'Abstract' |
|
88 | 88 | end |
|
89 | 89 | |
|
90 | 90 | def supports_cat? |
|
91 | 91 | true |
|
92 | 92 | end |
|
93 | 93 | |
|
94 | 94 | def supports_annotate? |
|
95 | 95 | respond_to?('annotate') |
|
96 | 96 | end |
|
97 | 97 | |
|
98 | 98 | def root_url |
|
99 | 99 | @root_url |
|
100 | 100 | end |
|
101 | 101 | |
|
102 | 102 | def url |
|
103 | 103 | @url |
|
104 | 104 | end |
|
105 | 105 | |
|
106 | 106 | def path_encoding |
|
107 | 107 | nil |
|
108 | 108 | end |
|
109 | 109 | |
|
110 | 110 | # get info about the svn repository |
|
111 | 111 | def info |
|
112 | 112 | return nil |
|
113 | 113 | end |
|
114 | 114 | |
|
115 | 115 | # Returns the entry identified by path and revision identifier |
|
116 | 116 | # or nil if entry doesn't exist in the repository |
|
117 | 117 | def entry(path=nil, identifier=nil) |
|
118 | 118 | parts = path.to_s.split(%r{[\/\\]}).select {|n| !n.blank?} |
|
119 | 119 | search_path = parts[0..-2].join('/') |
|
120 | 120 | search_name = parts[-1] |
|
121 | 121 | if search_path.blank? && search_name.blank? |
|
122 | 122 | # Root entry |
|
123 | 123 | Entry.new(:path => '', :kind => 'dir') |
|
124 | 124 | else |
|
125 | 125 | # Search for the entry in the parent directory |
|
126 | 126 | es = entries(search_path, identifier) |
|
127 | 127 | es ? es.detect {|e| e.name == search_name} : nil |
|
128 | 128 | end |
|
129 | 129 | end |
|
130 | 130 | |
|
131 | 131 | # Returns an Entries collection |
|
132 | 132 | # or nil if the given path doesn't exist in the repository |
|
133 | 133 | def entries(path=nil, identifier=nil, options={}) |
|
134 | 134 | return nil |
|
135 | 135 | end |
|
136 | 136 | |
|
137 | 137 | def branches |
|
138 | 138 | return nil |
|
139 | 139 | end |
|
140 | 140 | |
|
141 | 141 | def tags |
|
142 | 142 | return nil |
|
143 | 143 | end |
|
144 | 144 | |
|
145 | 145 | def default_branch |
|
146 | 146 | return nil |
|
147 | 147 | end |
|
148 | 148 | |
|
149 | 149 | def properties(path, identifier=nil) |
|
150 | 150 | return nil |
|
151 | 151 | end |
|
152 | 152 | |
|
153 | 153 | def revisions(path=nil, identifier_from=nil, identifier_to=nil, options={}) |
|
154 | 154 | return nil |
|
155 | 155 | end |
|
156 | 156 | |
|
157 | 157 | def diff(path, identifier_from, identifier_to=nil) |
|
158 | 158 | return nil |
|
159 | 159 | end |
|
160 | 160 | |
|
161 | 161 | def cat(path, identifier=nil) |
|
162 | 162 | return nil |
|
163 | 163 | end |
|
164 | 164 | |
|
165 | 165 | def with_leading_slash(path) |
|
166 | 166 | path ||= '' |
|
167 | 167 | (path[0,1]!="/") ? "/#{path}" : path |
|
168 | 168 | end |
|
169 | 169 | |
|
170 | 170 | def with_trailling_slash(path) |
|
171 | 171 | path ||= '' |
|
172 | 172 | (path[-1,1] == "/") ? path : "#{path}/" |
|
173 | 173 | end |
|
174 | 174 | |
|
175 | 175 | def without_leading_slash(path) |
|
176 | 176 | path ||= '' |
|
177 | 177 | path.gsub(%r{^/+}, '') |
|
178 | 178 | end |
|
179 | 179 | |
|
180 | 180 | def without_trailling_slash(path) |
|
181 | 181 | path ||= '' |
|
182 | 182 | (path[-1,1] == "/") ? path[0..-2] : path |
|
183 | 183 | end |
|
184 | 184 | |
|
185 | 185 | def shell_quote(str) |
|
186 | 186 | self.class.shell_quote(str) |
|
187 | 187 | end |
|
188 | 188 | |
|
189 | 189 | private |
|
190 | 190 | def retrieve_root_url |
|
191 | 191 | info = self.info |
|
192 | 192 | info ? info.root_url : nil |
|
193 | 193 | end |
|
194 | 194 | |
|
195 | 195 | def target(path, sq=true) |
|
196 | 196 | path ||= '' |
|
197 | 197 | base = path.match(/^\//) ? root_url : url |
|
198 | 198 | str = "#{base}/#{path}".gsub(/[?<>\*]/, '') |
|
199 | 199 | if sq |
|
200 | 200 | str = shell_quote(str) |
|
201 | 201 | end |
|
202 | 202 | str |
|
203 | 203 | end |
|
204 | 204 | |
|
205 | 205 | def logger |
|
206 | 206 | self.class.logger |
|
207 | 207 | end |
|
208 | 208 | |
|
209 | 209 | def shellout(cmd, options = {}, &block) |
|
210 | 210 | self.class.shellout(cmd, options, &block) |
|
211 | 211 | end |
|
212 | 212 | |
|
213 | 213 | def self.logger |
|
214 | 214 | Rails.logger |
|
215 | 215 | end |
|
216 | 216 | |
|
217 | 217 | def self.shellout(cmd, options = {}, &block) |
|
218 | 218 | if logger && logger.debug? |
|
219 | 219 | logger.debug "Shelling out: #{strip_credential(cmd)}" |
|
220 | 220 | end |
|
221 | 221 | if Rails.env == 'development' |
|
222 | 222 | # Capture stderr when running in dev environment |
|
223 | 223 | cmd = "#{cmd} 2>>#{shell_quote(Rails.root.join('log/scm.stderr.log').to_s)}" |
|
224 | 224 | end |
|
225 | 225 | begin |
|
226 | 226 | mode = "r+" |
|
227 | 227 | IO.popen(cmd, mode) do |io| |
|
228 | 228 | io.set_encoding("ASCII-8BIT") if io.respond_to?(:set_encoding) |
|
229 | 229 | io.close_write unless options[:write_stdin] |
|
230 | 230 | block.call(io) if block_given? |
|
231 | 231 | end |
|
232 | 232 | ## If scm command does not exist, |
|
233 | 233 | ## Linux JRuby 1.6.2 (ruby-1.8.7-p330) raises java.io.IOException |
|
234 | 234 | ## in production environment. |
|
235 | 235 | # rescue Errno::ENOENT => e |
|
236 | 236 | rescue Exception => e |
|
237 | 237 | msg = strip_credential(e.message) |
|
238 | 238 | # The command failed, log it and re-raise |
|
239 | 239 | logmsg = "SCM command failed, " |
|
240 | 240 | logmsg += "make sure that your SCM command (e.g. svn) is " |
|
241 | 241 | logmsg += "in PATH (#{ENV['PATH']})\n" |
|
242 | 242 | logmsg += "You can configure your scm commands in config/configuration.yml.\n" |
|
243 | 243 | logmsg += "#{strip_credential(cmd)}\n" |
|
244 | 244 | logmsg += "with: #{msg}" |
|
245 | 245 | logger.error(logmsg) |
|
246 | 246 | raise CommandFailed.new(msg) |
|
247 | 247 | end |
|
248 | 248 | end |
|
249 | 249 | |
|
250 | 250 | # Hides username/password in a given command |
|
251 | 251 | def self.strip_credential(cmd) |
|
252 | 252 | q = (Redmine::Platform.mswin? ? '"' : "'") |
|
253 | 253 | cmd.to_s.gsub(/(\-\-(password|username))\s+(#{q}[^#{q}]+#{q}|[^#{q}]\S+)/, '\\1 xxxx') |
|
254 | 254 | end |
|
255 | 255 | |
|
256 | 256 | def strip_credential(cmd) |
|
257 | 257 | self.class.strip_credential(cmd) |
|
258 | 258 | end |
|
259 | 259 | |
|
260 | 260 | def scm_iconv(to, from, str) |
|
261 | 261 | return nil if str.nil? |
|
262 | 262 | return str if to == from |
|
263 | 263 | if str.respond_to?(:force_encoding) |
|
264 | 264 | str.force_encoding(from) |
|
265 | 265 | begin |
|
266 | 266 | s = str.encode(to) |
|
267 | rescue Exception => e | |
|
267 | rescue Exception => err | |
|
268 | 268 | logger.error("failed to convert from #{from} to #{to}. #{err}") |
|
269 | 269 | nil |
|
270 | 270 | end |
|
271 | 271 | else |
|
272 | 272 | begin |
|
273 | 273 | Iconv.conv(to, from, str) |
|
274 | 274 | rescue Iconv::Failure => err |
|
275 | 275 | logger.error("failed to convert from #{from} to #{to}. #{err}") |
|
276 | 276 | nil |
|
277 | 277 | end |
|
278 | 278 | end |
|
279 | 279 | end |
|
280 | 280 | |
|
281 | 281 | def parse_xml(xml) |
|
282 | 282 | if RUBY_PLATFORM == 'java' |
|
283 | 283 | xml = xml.sub(%r{<\?xml[^>]*\?>}, '') |
|
284 | 284 | end |
|
285 | 285 | ActiveSupport::XmlMini.parse(xml) |
|
286 | 286 | end |
|
287 | 287 | end |
|
288 | 288 | |
|
289 | 289 | class Entries < Array |
|
290 | 290 | def sort_by_name |
|
291 | 291 | dup.sort! {|x,y| |
|
292 | 292 | if x.kind == y.kind |
|
293 | 293 | x.name.to_s <=> y.name.to_s |
|
294 | 294 | else |
|
295 | 295 | x.kind <=> y.kind |
|
296 | 296 | end |
|
297 | 297 | } |
|
298 | 298 | end |
|
299 | 299 | |
|
300 | 300 | def revisions |
|
301 | 301 | revisions ||= Revisions.new(collect{|entry| entry.lastrev}.compact) |
|
302 | 302 | end |
|
303 | 303 | end |
|
304 | 304 | |
|
305 | 305 | class Info |
|
306 | 306 | attr_accessor :root_url, :lastrev |
|
307 | 307 | def initialize(attributes={}) |
|
308 | 308 | self.root_url = attributes[:root_url] if attributes[:root_url] |
|
309 | 309 | self.lastrev = attributes[:lastrev] |
|
310 | 310 | end |
|
311 | 311 | end |
|
312 | 312 | |
|
313 | 313 | class Entry |
|
314 | 314 | attr_accessor :name, :path, :kind, :size, :lastrev, :changeset |
|
315 | 315 | |
|
316 | 316 | def initialize(attributes={}) |
|
317 | 317 | self.name = attributes[:name] if attributes[:name] |
|
318 | 318 | self.path = attributes[:path] if attributes[:path] |
|
319 | 319 | self.kind = attributes[:kind] if attributes[:kind] |
|
320 | 320 | self.size = attributes[:size].to_i if attributes[:size] |
|
321 | 321 | self.lastrev = attributes[:lastrev] |
|
322 | 322 | end |
|
323 | 323 | |
|
324 | 324 | def is_file? |
|
325 | 325 | 'file' == self.kind |
|
326 | 326 | end |
|
327 | 327 | |
|
328 | 328 | def is_dir? |
|
329 | 329 | 'dir' == self.kind |
|
330 | 330 | end |
|
331 | 331 | |
|
332 | 332 | def is_text? |
|
333 | 333 | Redmine::MimeType.is_type?('text', name) |
|
334 | 334 | end |
|
335 | 335 | |
|
336 | 336 | def author |
|
337 | 337 | if changeset |
|
338 | 338 | changeset.author.to_s |
|
339 | 339 | elsif lastrev |
|
340 | 340 | Redmine::CodesetUtil.replace_invalid_utf8(lastrev.author.to_s.split('<').first) |
|
341 | 341 | end |
|
342 | 342 | end |
|
343 | 343 | end |
|
344 | 344 | |
|
345 | 345 | class Revisions < Array |
|
346 | 346 | def latest |
|
347 | 347 | sort {|x,y| |
|
348 | 348 | unless x.time.nil? or y.time.nil? |
|
349 | 349 | x.time <=> y.time |
|
350 | 350 | else |
|
351 | 351 | 0 |
|
352 | 352 | end |
|
353 | 353 | }.last |
|
354 | 354 | end |
|
355 | 355 | end |
|
356 | 356 | |
|
357 | 357 | class Revision |
|
358 | 358 | attr_accessor :scmid, :name, :author, :time, :message, |
|
359 | 359 | :paths, :revision, :branch, :identifier, |
|
360 | 360 | :parents |
|
361 | 361 | |
|
362 | 362 | def initialize(attributes={}) |
|
363 | 363 | self.identifier = attributes[:identifier] |
|
364 | 364 | self.scmid = attributes[:scmid] |
|
365 | 365 | self.name = attributes[:name] || self.identifier |
|
366 | 366 | self.author = attributes[:author] |
|
367 | 367 | self.time = attributes[:time] |
|
368 | 368 | self.message = attributes[:message] || "" |
|
369 | 369 | self.paths = attributes[:paths] |
|
370 | 370 | self.revision = attributes[:revision] |
|
371 | 371 | self.branch = attributes[:branch] |
|
372 | 372 | self.parents = attributes[:parents] |
|
373 | 373 | end |
|
374 | 374 | |
|
375 | 375 | # Returns the readable identifier. |
|
376 | 376 | def format_identifier |
|
377 | 377 | self.identifier.to_s |
|
378 | 378 | end |
|
379 | 379 | |
|
380 | 380 | def ==(other) |
|
381 | 381 | if other.nil? |
|
382 | 382 | false |
|
383 | 383 | elsif scmid.present? |
|
384 | 384 | scmid == other.scmid |
|
385 | 385 | elsif identifier.present? |
|
386 | 386 | identifier == other.identifier |
|
387 | 387 | elsif revision.present? |
|
388 | 388 | revision == other.revision |
|
389 | 389 | end |
|
390 | 390 | end |
|
391 | 391 | end |
|
392 | 392 | |
|
393 | 393 | class Annotate |
|
394 | 394 | attr_reader :lines, :revisions |
|
395 | 395 | |
|
396 | 396 | def initialize |
|
397 | 397 | @lines = [] |
|
398 | 398 | @revisions = [] |
|
399 | 399 | end |
|
400 | 400 | |
|
401 | 401 | def add_line(line, revision) |
|
402 | 402 | @lines << line |
|
403 | 403 | @revisions << revision |
|
404 | 404 | end |
|
405 | 405 | |
|
406 | 406 | def content |
|
407 | 407 | content = lines.join("\n") |
|
408 | 408 | end |
|
409 | 409 | |
|
410 | 410 | def empty? |
|
411 | 411 | lines.empty? |
|
412 | 412 | end |
|
413 | 413 | end |
|
414 | 414 | |
|
415 | 415 | class Branch < String |
|
416 | 416 | attr_accessor :revision, :scmid |
|
417 | 417 | end |
|
418 | 418 | end |
|
419 | 419 | end |
|
420 | 420 | end |
@@ -1,581 +1,598 | |||
|
1 | 1 | # Redmine - project management software |
|
2 | 2 | # Copyright (C) 2006-2012 Jean-Philippe Lang |
|
3 | 3 | # |
|
4 | 4 | # This program is free software; you can redistribute it and/or |
|
5 | 5 | # modify it under the terms of the GNU General Public License |
|
6 | 6 | # as published by the Free Software Foundation; either version 2 |
|
7 | 7 | # of the License, or (at your option) any later version. |
|
8 | 8 | # |
|
9 | 9 | # This program is distributed in the hope that it will be useful, |
|
10 | 10 | # but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
11 | 11 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
12 | 12 | # GNU General Public License for more details. |
|
13 | 13 | # |
|
14 | 14 | # You should have received a copy of the GNU General Public License |
|
15 | 15 | # along with this program; if not, write to the Free Software |
|
16 | 16 | # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. |
|
17 | 17 | |
|
18 | 18 | require File.expand_path('../../../../../../test_helper', __FILE__) |
|
19 | 19 | begin |
|
20 | 20 | require 'mocha' |
|
21 | 21 | |
|
22 | 22 | class GitAdapterTest < ActiveSupport::TestCase |
|
23 | 23 | REPOSITORY_PATH = Rails.root.join('tmp/test/git_repository').to_s |
|
24 | 24 | |
|
25 | 25 | FELIX_HEX = "Felix Sch\xC3\xA4fer" |
|
26 | 26 | CHAR_1_HEX = "\xc3\x9c" |
|
27 | 27 | |
|
28 | 28 | ## Git, Mercurial and CVS path encodings are binary. |
|
29 | 29 | ## Subversion supports URL encoding for path. |
|
30 | 30 | ## Redmine Mercurial adapter and extension use URL encoding. |
|
31 | 31 | ## Git accepts only binary path in command line parameter. |
|
32 | 32 | ## So, there is no way to use binary command line parameter in JRuby. |
|
33 | 33 | JRUBY_SKIP = (RUBY_PLATFORM == 'java') |
|
34 | 34 | JRUBY_SKIP_STR = "TODO: This test fails in JRuby" |
|
35 | 35 | |
|
36 | 36 | if File.directory?(REPOSITORY_PATH) |
|
37 | 37 | ## Ruby uses ANSI api to fork a process on Windows. |
|
38 | 38 | ## Japanese Shift_JIS and Traditional Chinese Big5 have 0x5c(backslash) problem |
|
39 | 39 | ## and these are incompatible with ASCII. |
|
40 | 40 | ## Git for Windows (msysGit) changed internal API from ANSI to Unicode in 1.7.10 |
|
41 | 41 | ## http://code.google.com/p/msysgit/issues/detail?id=80 |
|
42 | 42 | ## So, Latin-1 path tests fail on Japanese Windows |
|
43 | 43 | WINDOWS_PASS = (Redmine::Platform.mswin? && |
|
44 | 44 | Redmine::Scm::Adapters::GitAdapter.client_version_above?([1, 7, 10])) |
|
45 | 45 | WINDOWS_SKIP_STR = "TODO: This test fails in Git for Windows above 1.7.10" |
|
46 | 46 | |
|
47 | 47 | def setup |
|
48 | 48 | adapter_class = Redmine::Scm::Adapters::GitAdapter |
|
49 | 49 | assert adapter_class |
|
50 | 50 | assert adapter_class.client_command |
|
51 | 51 | assert_equal true, adapter_class.client_available |
|
52 | 52 | assert_equal true, adapter_class.client_version_above?([1]) |
|
53 | 53 | assert_equal true, adapter_class.client_version_above?([1, 0]) |
|
54 | 54 | |
|
55 | 55 | @adapter = Redmine::Scm::Adapters::GitAdapter.new( |
|
56 | 56 | REPOSITORY_PATH, |
|
57 | 57 | nil, |
|
58 | 58 | nil, |
|
59 | 59 | nil, |
|
60 | 60 | 'ISO-8859-1' |
|
61 | 61 | ) |
|
62 | 62 | assert @adapter |
|
63 | 63 | @char_1 = CHAR_1_HEX.dup |
|
64 | 64 | if @char_1.respond_to?(:force_encoding) |
|
65 | 65 | @char_1.force_encoding('UTF-8') |
|
66 | 66 | end |
|
67 | 67 | end |
|
68 | 68 | |
|
69 | 69 | def test_scm_version |
|
70 | 70 | to_test = { "git version 1.7.3.4\n" => [1,7,3,4], |
|
71 | 71 | "1.6.1\n1.7\n1.8" => [1,6,1], |
|
72 | 72 | "1.6.2\r\n1.8.1\r\n1.9.1" => [1,6,2]} |
|
73 | 73 | to_test.each do |s, v| |
|
74 | 74 | test_scm_version_for(s, v) |
|
75 | 75 | end |
|
76 | 76 | end |
|
77 | 77 | |
|
78 | 78 | def test_branches |
|
79 | 79 | brs = [] |
|
80 | 80 | @adapter.branches.each do |b| |
|
81 | 81 | brs << b |
|
82 | 82 | end |
|
83 | 83 | assert_equal 6, brs.length |
|
84 | 84 | br_issue_8857 = brs[0] |
|
85 | 85 | assert_equal 'issue-8857', br_issue_8857.to_s |
|
86 | 86 | assert_equal '2a682156a3b6e77a8bf9cd4590e8db757f3c6c78', br_issue_8857.revision |
|
87 | 87 | assert_equal br_issue_8857.scmid, br_issue_8857.revision |
|
88 | 88 | assert_equal false, br_issue_8857.is_default |
|
89 | 89 | br_latin_1_path = brs[1] |
|
90 | 90 | assert_equal 'latin-1-path-encoding', br_latin_1_path.to_s |
|
91 | 91 | assert_equal '1ca7f5ed374f3cb31a93ae5215c2e25cc6ec5127', br_latin_1_path.revision |
|
92 | 92 | assert_equal br_latin_1_path.scmid, br_latin_1_path.revision |
|
93 | 93 | assert_equal false, br_latin_1_path.is_default |
|
94 | 94 | br_master = brs[2] |
|
95 | 95 | assert_equal 'master', br_master.to_s |
|
96 | 96 | assert_equal '83ca5fd546063a3c7dc2e568ba3355661a9e2b2c', br_master.revision |
|
97 | 97 | assert_equal br_master.scmid, br_master.revision |
|
98 | 98 | assert_equal false, br_master.is_default |
|
99 | 99 | br_master_20120212 = brs[3] |
|
100 | 100 | assert_equal 'master-20120212', br_master_20120212.to_s |
|
101 | 101 | assert_equal '83ca5fd546063a3c7dc2e568ba3355661a9e2b2c', br_master_20120212.revision |
|
102 | 102 | assert_equal br_master_20120212.scmid, br_master_20120212.revision |
|
103 | 103 | assert_equal true, br_master_20120212.is_default |
|
104 | 104 | br_latin_1 = brs[-2] |
|
105 | 105 | assert_equal 'test-latin-1', br_latin_1.to_s |
|
106 | 106 | assert_equal '67e7792ce20ccae2e4bb73eed09bb397819c8834', br_latin_1.revision |
|
107 | 107 | assert_equal br_latin_1.scmid, br_latin_1.revision |
|
108 | 108 | assert_equal false, br_latin_1.is_default |
|
109 | 109 | br_test = brs[-1] |
|
110 | 110 | assert_equal 'test_branch', br_test.to_s |
|
111 | 111 | assert_equal 'fba357b886984ee71185ad2065e65fc0417d9b92', br_test.revision |
|
112 | 112 | assert_equal br_test.scmid, br_test.revision |
|
113 | 113 | assert_equal false, br_test.is_default |
|
114 | 114 | end |
|
115 | 115 | |
|
116 | 116 | def test_default_branch |
|
117 | 117 | assert_equal 'master-20120212', @adapter.default_branch |
|
118 | 118 | end |
|
119 | 119 | |
|
120 | 120 | def test_tags |
|
121 | 121 | assert_equal [ |
|
122 | 122 | "tag00.lightweight", |
|
123 | 123 | "tag01.annotated", |
|
124 | 124 | ], @adapter.tags |
|
125 | 125 | end |
|
126 | 126 | |
|
127 | 127 | def test_revisions_master_all |
|
128 | 128 | revs1 = [] |
|
129 | 129 | @adapter.revisions('', nil, "master",{}) do |rev| |
|
130 | 130 | revs1 << rev |
|
131 | 131 | end |
|
132 | 132 | assert_equal 15, revs1.length |
|
133 | 133 | assert_equal '83ca5fd546063a3c7dc2e568ba3355661a9e2b2c', revs1[ 0].identifier |
|
134 | 134 | assert_equal '7234cb2750b63f47bff735edc50a1c0a433c2518', revs1[-1].identifier |
|
135 | 135 | |
|
136 | 136 | revs2 = [] |
|
137 | 137 | @adapter.revisions('', nil, "master", |
|
138 | 138 | {:reverse => true}) do |rev| |
|
139 | 139 | revs2 << rev |
|
140 | 140 | end |
|
141 | 141 | assert_equal 15, revs2.length |
|
142 | 142 | assert_equal '83ca5fd546063a3c7dc2e568ba3355661a9e2b2c', revs2[-1].identifier |
|
143 | 143 | assert_equal '7234cb2750b63f47bff735edc50a1c0a433c2518', revs2[ 0].identifier |
|
144 | 144 | end |
|
145 | 145 | |
|
146 | 146 | def test_revisions_master_merged_rev |
|
147 | 147 | revs1 = [] |
|
148 | 148 | @adapter.revisions('', |
|
149 | 149 | "713f4944648826f558cf548222f813dabe7cbb04", |
|
150 | 150 | "master", |
|
151 | 151 | {:reverse => true}) do |rev| |
|
152 | 152 | revs1 << rev |
|
153 | 153 | end |
|
154 | 154 | assert_equal 8, revs1.length |
|
155 | 155 | assert_equal 'fba357b886984ee71185ad2065e65fc0417d9b92', revs1[ 0].identifier |
|
156 | 156 | assert_equal '7e61ac704deecde634b51e59daa8110435dcb3da', revs1[ 1].identifier |
|
157 | 157 | # 4a07fe31b is not a child of 713f49446 |
|
158 | 158 | assert_equal '4a07fe31bffcf2888791f3e6cbc9c4545cefe3e8', revs1[ 2].identifier |
|
159 | 159 | # Merged revision |
|
160 | 160 | assert_equal '32ae898b720c2f7eec2723d5bdd558b4cb2d3ddf', revs1[ 3].identifier |
|
161 | 161 | assert_equal '83ca5fd546063a3c7dc2e568ba3355661a9e2b2c', revs1[-1].identifier |
|
162 | 162 | |
|
163 | 163 | revs2 = [] |
|
164 | 164 | @adapter.revisions('', |
|
165 | 165 | "fba357b886984ee71185ad2065e65fc0417d9b92", |
|
166 | 166 | "master", |
|
167 | 167 | {:reverse => true}) do |rev| |
|
168 | 168 | revs2 << rev |
|
169 | 169 | end |
|
170 | 170 | assert_equal 7, revs2.length |
|
171 | 171 | assert_equal '7e61ac704deecde634b51e59daa8110435dcb3da', revs2[ 0].identifier |
|
172 | 172 | # 4a07fe31b is not a child of fba357b8869 |
|
173 | 173 | assert_equal '4a07fe31bffcf2888791f3e6cbc9c4545cefe3e8', revs2[ 1].identifier |
|
174 | 174 | # Merged revision |
|
175 | 175 | assert_equal '32ae898b720c2f7eec2723d5bdd558b4cb2d3ddf', revs2[ 2].identifier |
|
176 | 176 | assert_equal '83ca5fd546063a3c7dc2e568ba3355661a9e2b2c', revs2[-1].identifier |
|
177 | 177 | end |
|
178 | 178 | |
|
179 | 179 | def test_revisions_branch_latin_1_path_encoding_all |
|
180 | 180 | revs1 = [] |
|
181 | 181 | @adapter.revisions('', nil, "latin-1-path-encoding",{}) do |rev| |
|
182 | 182 | revs1 << rev |
|
183 | 183 | end |
|
184 | 184 | assert_equal 8, revs1.length |
|
185 | 185 | assert_equal '1ca7f5ed374f3cb31a93ae5215c2e25cc6ec5127', revs1[ 0].identifier |
|
186 | 186 | assert_equal '7234cb2750b63f47bff735edc50a1c0a433c2518', revs1[-1].identifier |
|
187 | 187 | |
|
188 | 188 | revs2 = [] |
|
189 | 189 | @adapter.revisions('', nil, "latin-1-path-encoding", |
|
190 | 190 | {:reverse => true}) do |rev| |
|
191 | 191 | revs2 << rev |
|
192 | 192 | end |
|
193 | 193 | assert_equal 8, revs2.length |
|
194 | 194 | assert_equal '1ca7f5ed374f3cb31a93ae5215c2e25cc6ec5127', revs2[-1].identifier |
|
195 | 195 | assert_equal '7234cb2750b63f47bff735edc50a1c0a433c2518', revs2[ 0].identifier |
|
196 | 196 | end |
|
197 | 197 | |
|
198 | 198 | def test_revisions_branch_latin_1_path_encoding_with_rev |
|
199 | 199 | revs1 = [] |
|
200 | 200 | @adapter.revisions('', |
|
201 | 201 | '7234cb2750b63f47bff735edc50a1c0a433c2518', |
|
202 | 202 | "latin-1-path-encoding", |
|
203 | 203 | {:reverse => true}) do |rev| |
|
204 | 204 | revs1 << rev |
|
205 | 205 | end |
|
206 | 206 | assert_equal 7, revs1.length |
|
207 | 207 | assert_equal '899a15dba03a3b350b89c3f537e4bbe02a03cdc9', revs1[ 0].identifier |
|
208 | 208 | assert_equal '1ca7f5ed374f3cb31a93ae5215c2e25cc6ec5127', revs1[-1].identifier |
|
209 | 209 | |
|
210 | 210 | revs2 = [] |
|
211 | 211 | @adapter.revisions('', |
|
212 | 212 | '57ca437c0acbbcb749821fdf3726a1367056d364', |
|
213 | 213 | "latin-1-path-encoding", |
|
214 | 214 | {:reverse => true}) do |rev| |
|
215 | 215 | revs2 << rev |
|
216 | 216 | end |
|
217 | 217 | assert_equal 3, revs2.length |
|
218 | 218 | assert_equal '4fc55c43bf3d3dc2efb66145365ddc17639ce81e', revs2[ 0].identifier |
|
219 | 219 | assert_equal '1ca7f5ed374f3cb31a93ae5215c2e25cc6ec5127', revs2[-1].identifier |
|
220 | 220 | end |
|
221 | 221 | |
|
222 | 222 | def test_revisions_invalid_rev |
|
223 | 223 | assert_equal [], @adapter.revisions('', '1234abcd', "master") |
|
224 | 224 | assert_raise Redmine::Scm::Adapters::CommandFailed do |
|
225 | 225 | revs1 = [] |
|
226 | 226 | @adapter.revisions('', |
|
227 | 227 | '1234abcd', |
|
228 | 228 | "master", |
|
229 | 229 | {:reverse => true}) do |rev| |
|
230 | 230 | revs1 << rev |
|
231 | 231 | end |
|
232 | 232 | end |
|
233 | 233 | end |
|
234 | 234 | |
|
235 | 235 | def test_revisions_includes_master_two_revs |
|
236 | 236 | revs1 = [] |
|
237 | 237 | @adapter.revisions('', nil, nil, |
|
238 | 238 | {:reverse => true, |
|
239 | 239 | :includes => ['83ca5fd546063a3c7dc2e568ba3355661a9e2b2c'], |
|
240 | 240 | :excludes => ['4f26664364207fa8b1af9f8722647ab2d4ac5d43']}) do |rev| |
|
241 | 241 | revs1 << rev |
|
242 | 242 | end |
|
243 | 243 | assert_equal 2, revs1.length |
|
244 | 244 | assert_equal 'ed5bb786bbda2dee66a2d50faf51429dbc043a7b', revs1[ 0].identifier |
|
245 | 245 | assert_equal '83ca5fd546063a3c7dc2e568ba3355661a9e2b2c', revs1[-1].identifier |
|
246 | 246 | end |
|
247 | 247 | |
|
248 | 248 | def test_revisions_includes_master_two_revs_from_origin |
|
249 | 249 | revs1 = [] |
|
250 | 250 | @adapter.revisions('', nil, nil, |
|
251 | 251 | {:reverse => true, |
|
252 | 252 | :includes => ['899a15dba03a3b350b89c3f537e4bbe02a03cdc9'], |
|
253 | 253 | :excludes => []}) do |rev| |
|
254 | 254 | revs1 << rev |
|
255 | 255 | end |
|
256 | 256 | assert_equal 2, revs1.length |
|
257 | 257 | assert_equal '7234cb2750b63f47bff735edc50a1c0a433c2518', revs1[ 0].identifier |
|
258 | 258 | assert_equal '899a15dba03a3b350b89c3f537e4bbe02a03cdc9', revs1[ 1].identifier |
|
259 | 259 | end |
|
260 | 260 | |
|
261 | 261 | def test_revisions_includes_merged_revs |
|
262 | 262 | revs1 = [] |
|
263 | 263 | @adapter.revisions('', nil, nil, |
|
264 | 264 | {:reverse => true, |
|
265 | 265 | :includes => ['83ca5fd546063a3c7dc2e568ba3355661a9e2b2c'], |
|
266 | 266 | :excludes => ['fba357b886984ee71185ad2065e65fc0417d9b92']}) do |rev| |
|
267 | 267 | revs1 << rev |
|
268 | 268 | end |
|
269 | 269 | assert_equal 7, revs1.length |
|
270 | 270 | assert_equal '7e61ac704deecde634b51e59daa8110435dcb3da', revs1[ 0].identifier |
|
271 | 271 | assert_equal '4a07fe31bffcf2888791f3e6cbc9c4545cefe3e8', revs1[ 1].identifier |
|
272 | 272 | assert_equal '32ae898b720c2f7eec2723d5bdd558b4cb2d3ddf', revs1[ 2].identifier |
|
273 | 273 | assert_equal '83ca5fd546063a3c7dc2e568ba3355661a9e2b2c', revs1[-1].identifier |
|
274 | 274 | end |
|
275 | 275 | |
|
276 | 276 | def test_revisions_includes_two_heads |
|
277 | 277 | revs1 = [] |
|
278 | 278 | @adapter.revisions('', nil, nil, |
|
279 | 279 | {:reverse => true, |
|
280 | 280 | :includes => ['83ca5fd546063a3c7dc2e568ba3355661a9e2b2c', |
|
281 | 281 | '1ca7f5ed374f3cb31a93ae5215c2e25cc6ec5127'], |
|
282 | 282 | :excludes => ['4f26664364207fa8b1af9f8722647ab2d4ac5d43', |
|
283 | 283 | '4fc55c43bf3d3dc2efb66145365ddc17639ce81e']}) do |rev| |
|
284 | 284 | revs1 << rev |
|
285 | 285 | end |
|
286 | 286 | assert_equal 4, revs1.length |
|
287 | 287 | assert_equal 'ed5bb786bbda2dee66a2d50faf51429dbc043a7b', revs1[ 0].identifier |
|
288 | 288 | assert_equal '83ca5fd546063a3c7dc2e568ba3355661a9e2b2c', revs1[ 1].identifier |
|
289 | 289 | assert_equal '64f1f3e89ad1cb57976ff0ad99a107012ba3481d', revs1[-2].identifier |
|
290 | 290 | assert_equal '1ca7f5ed374f3cb31a93ae5215c2e25cc6ec5127', revs1[-1].identifier |
|
291 | 291 | end |
|
292 | 292 | |
|
293 | 293 | def test_revisions_disjointed_histories_revisions |
|
294 | 294 | revs1 = [] |
|
295 | 295 | @adapter.revisions('', nil, nil, |
|
296 | 296 | {:reverse => true, |
|
297 | 297 | :includes => ['83ca5fd546063a3c7dc2e568ba3355661a9e2b2c', |
|
298 | 298 | '92397af84d22f27389c822848ecd5b463c181583'], |
|
299 | 299 | :excludes => ['95488a44bc25f7d1f97d775a31359539ff333a63', |
|
300 | 300 | '4f26664364207fa8b1af9f8722647ab2d4ac5d43'] }) do |rev| |
|
301 | 301 | revs1 << rev |
|
302 | 302 | end |
|
303 | 303 | assert_equal 4, revs1.length |
|
304 | 304 | assert_equal 'ed5bb786bbda2dee66a2d50faf51429dbc043a7b', revs1[ 0].identifier |
|
305 | 305 | assert_equal '83ca5fd546063a3c7dc2e568ba3355661a9e2b2c', revs1[ 1].identifier |
|
306 | 306 | assert_equal 'bc201c95999c4f10d018b0aa03b541cd6a2ff0ee', revs1[-2].identifier |
|
307 | 307 | assert_equal '92397af84d22f27389c822848ecd5b463c181583', revs1[-1].identifier |
|
308 | 308 | end |
|
309 | 309 | |
|
310 | 310 | def test_revisions_invalid_rev_excludes |
|
311 | 311 | assert_equal [], |
|
312 | 312 | @adapter.revisions('', nil, nil, |
|
313 | 313 | {:reverse => true, |
|
314 | 314 | :includes => ['83ca5fd546063a3c7dc2e568ba3355661a9e2b2c'], |
|
315 | 315 | :excludes => ['0123abcd4567']}) |
|
316 | 316 | assert_raise Redmine::Scm::Adapters::CommandFailed do |
|
317 | 317 | revs1 = [] |
|
318 | 318 | @adapter.revisions('', nil, nil, |
|
319 | 319 | {:reverse => true, |
|
320 | 320 | :includes => ['83ca5fd546063a3c7dc2e568ba3355661a9e2b2c'], |
|
321 | 321 | :excludes => ['0123abcd4567']}) do |rev| |
|
322 | 322 | revs1 << rev |
|
323 | 323 | end |
|
324 | 324 | end |
|
325 | 325 | end |
|
326 | 326 | |
|
327 | 327 | def test_getting_revisions_with_spaces_in_filename |
|
328 | 328 | assert_equal 1, @adapter.revisions("filemane with spaces.txt", |
|
329 | 329 | nil, "master").length |
|
330 | 330 | end |
|
331 | 331 | |
|
332 | 332 | def test_parents |
|
333 | 333 | revs1 = [] |
|
334 | 334 | @adapter.revisions('', |
|
335 | 335 | nil, |
|
336 | 336 | "master", |
|
337 | 337 | {:reverse => true}) do |rev| |
|
338 | 338 | revs1 << rev |
|
339 | 339 | end |
|
340 | 340 | assert_equal 15, revs1.length |
|
341 | 341 | assert_equal "7234cb2750b63f47bff735edc50a1c0a433c2518", |
|
342 | 342 | revs1[0].identifier |
|
343 | 343 | assert_equal nil, revs1[0].parents |
|
344 | 344 | assert_equal "899a15dba03a3b350b89c3f537e4bbe02a03cdc9", |
|
345 | 345 | revs1[1].identifier |
|
346 | 346 | assert_equal 1, revs1[1].parents.length |
|
347 | 347 | assert_equal "7234cb2750b63f47bff735edc50a1c0a433c2518", |
|
348 | 348 | revs1[1].parents[0] |
|
349 | 349 | assert_equal "32ae898b720c2f7eec2723d5bdd558b4cb2d3ddf", |
|
350 | 350 | revs1[10].identifier |
|
351 | 351 | assert_equal 2, revs1[10].parents.length |
|
352 | 352 | assert_equal "4a07fe31bffcf2888791f3e6cbc9c4545cefe3e8", |
|
353 | 353 | revs1[10].parents[0] |
|
354 | 354 | assert_equal "7e61ac704deecde634b51e59daa8110435dcb3da", |
|
355 | 355 | revs1[10].parents[1] |
|
356 | 356 | end |
|
357 | 357 | |
|
358 | 358 | def test_getting_revisions_with_leading_and_trailing_spaces_in_filename |
|
359 | 359 | assert_equal " filename with a leading space.txt ", |
|
360 | 360 | @adapter.revisions(" filename with a leading space.txt ", |
|
361 | 361 | nil, "master")[0].paths[0][:path] |
|
362 | 362 | end |
|
363 | 363 | |
|
364 | 364 | def test_getting_entries_with_leading_and_trailing_spaces_in_filename |
|
365 | 365 | assert_equal " filename with a leading space.txt ", |
|
366 | 366 | @adapter.entries('', |
|
367 | 367 | '83ca5fd546063a3c7dc2e568ba3355661a9e2b2c')[3].name |
|
368 | 368 | end |
|
369 | 369 | |
|
370 | 370 | def test_annotate |
|
371 | 371 | annotate = @adapter.annotate('sources/watchers_controller.rb') |
|
372 | 372 | assert_kind_of Redmine::Scm::Adapters::Annotate, annotate |
|
373 | 373 | assert_equal 41, annotate.lines.size |
|
374 | 374 | assert_equal "# This program is free software; you can redistribute it and/or", |
|
375 | 375 | annotate.lines[4].strip |
|
376 | 376 | assert_equal "7234cb2750b63f47bff735edc50a1c0a433c2518", |
|
377 | 377 | annotate.revisions[4].identifier |
|
378 | 378 | assert_equal "jsmith", annotate.revisions[4].author |
|
379 | 379 | end |
|
380 | 380 | |
|
381 | 381 | def test_annotate_moved_file |
|
382 | 382 | annotate = @adapter.annotate('renamed_test.txt') |
|
383 | 383 | assert_kind_of Redmine::Scm::Adapters::Annotate, annotate |
|
384 | 384 | assert_equal 2, annotate.lines.size |
|
385 | 385 | end |
|
386 | 386 | |
|
387 | 387 | def test_last_rev |
|
388 | 388 | last_rev = @adapter.lastrev("README", |
|
389 | 389 | "4f26664364207fa8b1af9f8722647ab2d4ac5d43") |
|
390 | 390 | assert_equal "4a07fe31bffcf2888791f3e6cbc9c4545cefe3e8", last_rev.scmid |
|
391 | 391 | assert_equal "4a07fe31bffcf2888791f3e6cbc9c4545cefe3e8", last_rev.identifier |
|
392 | 392 | assert_equal "Adam Soltys <asoltys@gmail.com>", last_rev.author |
|
393 | 393 | assert_equal "2009-06-24 05:27:38".to_time, last_rev.time |
|
394 | 394 | end |
|
395 | 395 | |
|
396 | 396 | def test_last_rev_with_spaces_in_filename |
|
397 | 397 | last_rev = @adapter.lastrev("filemane with spaces.txt", |
|
398 | 398 | "ed5bb786bbda2dee66a2d50faf51429dbc043a7b") |
|
399 | 399 | str_felix_hex = FELIX_HEX.dup |
|
400 | 400 | last_rev_author = last_rev.author |
|
401 | 401 | if last_rev_author.respond_to?(:force_encoding) |
|
402 | 402 | str_felix_hex.force_encoding('ASCII-8BIT') |
|
403 | 403 | end |
|
404 | 404 | assert_equal "ed5bb786bbda2dee66a2d50faf51429dbc043a7b", last_rev.scmid |
|
405 | 405 | assert_equal "ed5bb786bbda2dee66a2d50faf51429dbc043a7b", last_rev.identifier |
|
406 | 406 | assert_equal "#{str_felix_hex} <felix@fachschaften.org>", |
|
407 | 407 | last_rev.author |
|
408 | 408 | assert_equal "2010-09-18 19:59:46".to_time, last_rev.time |
|
409 | 409 | end |
|
410 | 410 | |
|
411 | 411 | def test_latin_1_path |
|
412 | 412 | if WINDOWS_PASS |
|
413 | 413 | puts WINDOWS_SKIP_STR |
|
414 | 414 | elsif JRUBY_SKIP |
|
415 | 415 | puts JRUBY_SKIP_STR |
|
416 | 416 | else |
|
417 | 417 | p2 = "latin-1-dir/test-#{@char_1}-2.txt" |
|
418 | 418 | ['4fc55c43bf3d3dc2efb66145365ddc17639ce81e', '4fc55c43bf3'].each do |r1| |
|
419 | 419 | assert @adapter.diff(p2, r1) |
|
420 | 420 | assert @adapter.cat(p2, r1) |
|
421 | 421 | assert_equal 1, @adapter.annotate(p2, r1).lines.length |
|
422 | 422 | ['64f1f3e89ad1cb57976ff0ad99a107012ba3481d', '64f1f3e89ad1cb5797'].each do |r2| |
|
423 | 423 | assert @adapter.diff(p2, r1, r2) |
|
424 | 424 | end |
|
425 | 425 | end |
|
426 | 426 | end |
|
427 | 427 | end |
|
428 | 428 | |
|
429 | 429 | def test_entries_tag |
|
430 | 430 | entries1 = @adapter.entries(nil, 'tag01.annotated', |
|
431 | 431 | options = {:report_last_commit => true}) |
|
432 | 432 | assert entries1 |
|
433 | 433 | assert_equal 3, entries1.size |
|
434 | 434 | assert_equal 'sources', entries1[1].name |
|
435 | 435 | assert_equal 'sources', entries1[1].path |
|
436 | 436 | assert_equal 'dir', entries1[1].kind |
|
437 | 437 | readme = entries1[2] |
|
438 | 438 | assert_equal 'README', readme.name |
|
439 | 439 | assert_equal 'README', readme.path |
|
440 | 440 | assert_equal 'file', readme.kind |
|
441 | 441 | assert_equal 27, readme.size |
|
442 | 442 | assert_equal '899a15dba03a3b350b89c3f537e4bbe02a03cdc9', readme.lastrev.identifier |
|
443 | 443 | assert_equal Time.gm(2007, 12, 14, 9, 24, 1), readme.lastrev.time |
|
444 | 444 | end |
|
445 | 445 | |
|
446 | 446 | def test_entries_branch |
|
447 | 447 | entries1 = @adapter.entries(nil, 'test_branch', |
|
448 | 448 | options = {:report_last_commit => true}) |
|
449 | 449 | assert entries1 |
|
450 | 450 | assert_equal 4, entries1.size |
|
451 | 451 | assert_equal 'sources', entries1[1].name |
|
452 | 452 | assert_equal 'sources', entries1[1].path |
|
453 | 453 | assert_equal 'dir', entries1[1].kind |
|
454 | 454 | readme = entries1[2] |
|
455 | 455 | assert_equal 'README', readme.name |
|
456 | 456 | assert_equal 'README', readme.path |
|
457 | 457 | assert_equal 'file', readme.kind |
|
458 | 458 | assert_equal 159, readme.size |
|
459 | 459 | assert_equal '713f4944648826f558cf548222f813dabe7cbb04', readme.lastrev.identifier |
|
460 | 460 | assert_equal Time.gm(2009, 6, 19, 4, 37, 23), readme.lastrev.time |
|
461 | 461 | end |
|
462 | 462 | |
|
463 | def test_entries_wrong_path_encoding | |
|
464 | adpt = Redmine::Scm::Adapters::GitAdapter.new( | |
|
465 | REPOSITORY_PATH, | |
|
466 | nil, | |
|
467 | nil, | |
|
468 | nil, | |
|
469 | 'EUC-JP' | |
|
470 | ) | |
|
471 | entries1 = adpt.entries('latin-1-dir', '64f1f3e8') | |
|
472 | assert entries1 | |
|
473 | assert_equal 3, entries1.size | |
|
474 | f1 = entries1[1] | |
|
475 | assert_equal nil, f1.name | |
|
476 | assert_equal nil, f1.path | |
|
477 | assert_equal 'file', f1.kind | |
|
478 | end | |
|
479 | ||
|
463 | 480 | def test_entries_latin_1_files |
|
464 | 481 | entries1 = @adapter.entries('latin-1-dir', '64f1f3e8') |
|
465 | 482 | assert entries1 |
|
466 | 483 | assert_equal 3, entries1.size |
|
467 | 484 | f1 = entries1[1] |
|
468 | 485 | assert_equal "test-#{@char_1}-2.txt", f1.name |
|
469 | 486 | assert_equal "latin-1-dir/test-#{@char_1}-2.txt", f1.path |
|
470 | 487 | assert_equal 'file', f1.kind |
|
471 | 488 | end |
|
472 | 489 | |
|
473 | 490 | def test_entries_latin_1_dir |
|
474 | 491 | if WINDOWS_PASS |
|
475 | 492 | puts WINDOWS_SKIP_STR |
|
476 | 493 | elsif JRUBY_SKIP |
|
477 | 494 | puts JRUBY_SKIP_STR |
|
478 | 495 | else |
|
479 | 496 | entries1 = @adapter.entries("latin-1-dir/test-#{@char_1}-subdir", |
|
480 | 497 | '1ca7f5ed') |
|
481 | 498 | assert entries1 |
|
482 | 499 | assert_equal 3, entries1.size |
|
483 | 500 | f1 = entries1[1] |
|
484 | 501 | assert_equal "test-#{@char_1}-2.txt", f1.name |
|
485 | 502 | assert_equal "latin-1-dir/test-#{@char_1}-subdir/test-#{@char_1}-2.txt", f1.path |
|
486 | 503 | assert_equal 'file', f1.kind |
|
487 | 504 | end |
|
488 | 505 | end |
|
489 | 506 | |
|
490 | 507 | def test_entry |
|
491 | 508 | entry = @adapter.entry() |
|
492 | 509 | assert_equal "", entry.path |
|
493 | 510 | assert_equal "dir", entry.kind |
|
494 | 511 | entry = @adapter.entry('') |
|
495 | 512 | assert_equal "", entry.path |
|
496 | 513 | assert_equal "dir", entry.kind |
|
497 | 514 | assert_nil @adapter.entry('invalid') |
|
498 | 515 | assert_nil @adapter.entry('/invalid') |
|
499 | 516 | assert_nil @adapter.entry('/invalid/') |
|
500 | 517 | assert_nil @adapter.entry('invalid/invalid') |
|
501 | 518 | assert_nil @adapter.entry('invalid/invalid/') |
|
502 | 519 | assert_nil @adapter.entry('/invalid/invalid') |
|
503 | 520 | assert_nil @adapter.entry('/invalid/invalid/') |
|
504 | 521 | ["README", "/README"].each do |path| |
|
505 | 522 | entry = @adapter.entry(path, '7234cb2750b63f') |
|
506 | 523 | assert_equal "README", entry.path |
|
507 | 524 | assert_equal "file", entry.kind |
|
508 | 525 | end |
|
509 | 526 | ["sources", "/sources", "/sources/"].each do |path| |
|
510 | 527 | entry = @adapter.entry(path, '7234cb2750b63f') |
|
511 | 528 | assert_equal "sources", entry.path |
|
512 | 529 | assert_equal "dir", entry.kind |
|
513 | 530 | end |
|
514 | 531 | ["sources/watchers_controller.rb", "/sources/watchers_controller.rb"].each do |path| |
|
515 | 532 | entry = @adapter.entry(path, '7234cb2750b63f') |
|
516 | 533 | assert_equal "sources/watchers_controller.rb", entry.path |
|
517 | 534 | assert_equal "file", entry.kind |
|
518 | 535 | end |
|
519 | 536 | end |
|
520 | 537 | |
|
521 | 538 | def test_path_encoding_default_utf8 |
|
522 | 539 | adpt1 = Redmine::Scm::Adapters::GitAdapter.new( |
|
523 | 540 | REPOSITORY_PATH |
|
524 | 541 | ) |
|
525 | 542 | assert_equal "UTF-8", adpt1.path_encoding |
|
526 | 543 | adpt2 = Redmine::Scm::Adapters::GitAdapter.new( |
|
527 | 544 | REPOSITORY_PATH, |
|
528 | 545 | nil, |
|
529 | 546 | nil, |
|
530 | 547 | nil, |
|
531 | 548 | "" |
|
532 | 549 | ) |
|
533 | 550 | assert_equal "UTF-8", adpt2.path_encoding |
|
534 | 551 | end |
|
535 | 552 | |
|
536 | 553 | def test_cat_path_invalid |
|
537 | 554 | assert_nil @adapter.cat('invalid') |
|
538 | 555 | end |
|
539 | 556 | |
|
540 | 557 | def test_cat_revision_invalid |
|
541 | 558 | assert @adapter.cat('README') |
|
542 | 559 | assert_nil @adapter.cat('README', '1234abcd5678') |
|
543 | 560 | end |
|
544 | 561 | |
|
545 | 562 | def test_diff_path_invalid |
|
546 | 563 | assert_equal [], @adapter.diff('invalid', '713f4944648826f5') |
|
547 | 564 | end |
|
548 | 565 | |
|
549 | 566 | def test_diff_revision_invalid |
|
550 | 567 | assert_nil @adapter.diff(nil, '1234abcd5678') |
|
551 | 568 | assert_nil @adapter.diff(nil, '713f4944648826f5', '1234abcd5678') |
|
552 | 569 | assert_nil @adapter.diff(nil, '1234abcd5678', '713f4944648826f5') |
|
553 | 570 | end |
|
554 | 571 | |
|
555 | 572 | def test_annotate_path_invalid |
|
556 | 573 | assert_nil @adapter.annotate('invalid') |
|
557 | 574 | end |
|
558 | 575 | |
|
559 | 576 | def test_annotate_revision_invalid |
|
560 | 577 | assert @adapter.annotate('README') |
|
561 | 578 | assert_nil @adapter.annotate('README', '1234abcd5678') |
|
562 | 579 | end |
|
563 | 580 | |
|
564 | 581 | private |
|
565 | 582 | |
|
566 | 583 | def test_scm_version_for(scm_command_version, version) |
|
567 | 584 | @adapter.class.expects(:scm_version_from_command_line).returns(scm_command_version) |
|
568 | 585 | assert_equal version, @adapter.class.scm_command_version |
|
569 | 586 | end |
|
570 | 587 | |
|
571 | 588 | else |
|
572 | 589 | puts "Git test repository NOT FOUND. Skipping unit tests !!!" |
|
573 | 590 | def test_fake; assert true end |
|
574 | 591 | end |
|
575 | 592 | end |
|
576 | 593 | |
|
577 | 594 | rescue LoadError |
|
578 | 595 | class GitMochaFake < ActiveSupport::TestCase |
|
579 | 596 | def test_fake; assert(false, "Requires mocha to run those tests") end |
|
580 | 597 | end |
|
581 | 598 | end |
General Comments 0
You need to be logged in to leave comments.
Login now