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