@@ -1,377 +1,389 | |||
|
1 | 1 | # Redmine - project management software |
|
2 | 2 | # Copyright (C) 2006-2014 Jean-Philippe Lang |
|
3 | 3 | # |
|
4 | 4 | # This program is free software; you can redistribute it and/or |
|
5 | 5 | # modify it under the terms of the GNU General Public License |
|
6 | 6 | # as published by the Free Software Foundation; either version 2 |
|
7 | 7 | # of the License, or (at your option) any later version. |
|
8 | 8 | # |
|
9 | 9 | # This program is distributed in the hope that it will be useful, |
|
10 | 10 | # but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
11 | 11 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
12 | 12 | # GNU General Public License for more details. |
|
13 | 13 | # |
|
14 | 14 | # You should have received a copy of the GNU General Public License |
|
15 | 15 | # along with this program; if not, write to the Free Software |
|
16 | 16 | # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. |
|
17 | 17 | |
|
18 | 18 | require File.expand_path('../../test_helper', __FILE__) |
|
19 | 19 | |
|
20 | 20 | class RepositoryMercurialTest < ActiveSupport::TestCase |
|
21 | 21 | fixtures :projects |
|
22 | 22 | |
|
23 | 23 | include Redmine::I18n |
|
24 | 24 | |
|
25 | 25 | REPOSITORY_PATH = Rails.root.join('tmp/test/mercurial_repository').to_s |
|
26 | 26 | NUM_REV = 32 |
|
27 | 27 | CHAR_1_HEX = "\xc3\x9c" |
|
28 | 28 | |
|
29 | 29 | def setup |
|
30 | 30 | @project = Project.find(3) |
|
31 | 31 | @repository = Repository::Mercurial.create( |
|
32 | 32 | :project => @project, |
|
33 | 33 | :url => REPOSITORY_PATH, |
|
34 | 34 | :path_encoding => 'ISO-8859-1' |
|
35 | 35 | ) |
|
36 | 36 | assert @repository |
|
37 | 37 | @char_1 = CHAR_1_HEX.dup |
|
38 | 38 | @tag_char_1 = "tag-#{CHAR_1_HEX}-00" |
|
39 | 39 | @branch_char_0 = "branch-#{CHAR_1_HEX}-00" |
|
40 | 40 | @branch_char_1 = "branch-#{CHAR_1_HEX}-01" |
|
41 | 41 | if @char_1.respond_to?(:force_encoding) |
|
42 | 42 | @char_1.force_encoding('UTF-8') |
|
43 | 43 | @tag_char_1.force_encoding('UTF-8') |
|
44 | 44 | @branch_char_0.force_encoding('UTF-8') |
|
45 | 45 | @branch_char_1.force_encoding('UTF-8') |
|
46 | 46 | end |
|
47 | 47 | end |
|
48 | 48 | |
|
49 | 49 | def test_blank_path_to_repository_error_message |
|
50 | 50 | set_language_if_valid 'en' |
|
51 | 51 | repo = Repository::Mercurial.new( |
|
52 | 52 | :project => @project, |
|
53 | 53 | :identifier => 'test' |
|
54 | 54 | ) |
|
55 | 55 | assert !repo.save |
|
56 | 56 | assert_include "Path to repository can't be blank", |
|
57 | 57 | repo.errors.full_messages |
|
58 | 58 | end |
|
59 | 59 | |
|
60 | 60 | def test_blank_path_to_repository_error_message_fr |
|
61 | 61 | set_language_if_valid 'fr' |
|
62 | 62 | str = "Chemin du d\xc3\xa9p\xc3\xb4t doit \xc3\xaatre renseign\xc3\xa9(e)" |
|
63 | 63 | str.force_encoding('UTF-8') if str.respond_to?(:force_encoding) |
|
64 | 64 | repo = Repository::Mercurial.new( |
|
65 | 65 | :project => @project, |
|
66 | 66 | :url => "", |
|
67 | 67 | :identifier => 'test', |
|
68 | 68 | :path_encoding => '' |
|
69 | 69 | ) |
|
70 | 70 | assert !repo.save |
|
71 | 71 | assert_include str, repo.errors.full_messages |
|
72 | 72 | end |
|
73 | 73 | |
|
74 | 74 | if File.directory?(REPOSITORY_PATH) |
|
75 | 75 | def test_scm_available |
|
76 | 76 | klass = Repository::Mercurial |
|
77 | 77 | assert_equal "Mercurial", klass.scm_name |
|
78 | 78 | assert klass.scm_adapter_class |
|
79 | 79 | assert_not_equal "", klass.scm_command |
|
80 | 80 | assert_equal true, klass.scm_available |
|
81 | 81 | end |
|
82 | 82 | |
|
83 | 83 | def test_entries |
|
84 | 84 | entries = @repository.entries |
|
85 | 85 | assert_kind_of Redmine::Scm::Adapters::Entries, entries |
|
86 | 86 | end |
|
87 | 87 | |
|
88 | 88 | def test_fetch_changesets_from_scratch |
|
89 | 89 | assert_equal 0, @repository.changesets.count |
|
90 | 90 | @repository.fetch_changesets |
|
91 | 91 | @project.reload |
|
92 | 92 | assert_equal NUM_REV, @repository.changesets.count |
|
93 | 93 | assert_equal 46, @repository.filechanges.count |
|
94 | 94 | assert_equal "Initial import.\nThe repository contains 3 files.", |
|
95 | 95 | @repository.changesets.find_by_revision('0').comments |
|
96 | 96 | end |
|
97 | 97 | |
|
98 | 98 | def test_fetch_changesets_incremental |
|
99 | 99 | assert_equal 0, @repository.changesets.count |
|
100 | 100 | @repository.fetch_changesets |
|
101 | 101 | @project.reload |
|
102 | 102 | assert_equal NUM_REV, @repository.changesets.count |
|
103 | 103 | # Remove changesets with revision > 2 |
|
104 | 104 | @repository.changesets.each {|c| c.destroy if c.revision.to_i > 2} |
|
105 | 105 | @project.reload |
|
106 | 106 | @repository.reload |
|
107 | 107 | assert_equal 3, @repository.changesets.count |
|
108 | 108 | |
|
109 | 109 | @repository.fetch_changesets |
|
110 | 110 | @project.reload |
|
111 | 111 | assert_equal NUM_REV, @repository.changesets.count |
|
112 | 112 | end |
|
113 | 113 | |
|
114 | 114 | def test_isodatesec |
|
115 | 115 | # Template keyword 'isodatesec' supported in Mercurial 1.0 and higher |
|
116 | 116 | if @repository.scm.class.client_version_above?([1, 0]) |
|
117 | 117 | assert_equal 0, @repository.changesets.count |
|
118 | 118 | @repository.fetch_changesets |
|
119 | 119 | @project.reload |
|
120 | 120 | assert_equal NUM_REV, @repository.changesets.count |
|
121 | 121 | rev0_committed_on = Time.gm(2007, 12, 14, 9, 22, 52) |
|
122 | 122 | assert_equal @repository.changesets.find_by_revision('0').committed_on, rev0_committed_on |
|
123 | 123 | end |
|
124 | 124 | end |
|
125 | 125 | |
|
126 | 126 | def test_changeset_order_by_revision |
|
127 | 127 | assert_equal 0, @repository.changesets.count |
|
128 | 128 | @repository.fetch_changesets |
|
129 | 129 | @project.reload |
|
130 | 130 | assert_equal NUM_REV, @repository.changesets.count |
|
131 | 131 | |
|
132 | 132 | c0 = @repository.latest_changeset |
|
133 | 133 | c1 = @repository.changesets.find_by_revision('0') |
|
134 | 134 | # sorted by revision (id), not by date |
|
135 | 135 | assert c0.revision.to_i > c1.revision.to_i |
|
136 | 136 | assert c0.committed_on < c1.committed_on |
|
137 | 137 | end |
|
138 | 138 | |
|
139 | 139 | def test_latest_changesets |
|
140 | 140 | assert_equal 0, @repository.changesets.count |
|
141 | 141 | @repository.fetch_changesets |
|
142 | 142 | @project.reload |
|
143 | 143 | assert_equal NUM_REV, @repository.changesets.count |
|
144 | 144 | |
|
145 | 145 | # with_limit |
|
146 | 146 | changesets = @repository.latest_changesets('', nil, 2) |
|
147 | 147 | assert_equal %w|31 30|, changesets.collect(&:revision) |
|
148 | 148 | |
|
149 | 149 | # with_filepath |
|
150 | 150 | changesets = @repository.latest_changesets( |
|
151 | 151 | '/sql_escape/percent%dir/percent%file1.txt', nil) |
|
152 | 152 | assert_equal %w|30 11 10 9|, changesets.collect(&:revision) |
|
153 | 153 | |
|
154 | 154 | changesets = @repository.latest_changesets( |
|
155 | 155 | '/sql_escape/underscore_dir/understrike_file.txt', nil) |
|
156 | 156 | assert_equal %w|30 12 9|, changesets.collect(&:revision) |
|
157 | 157 | |
|
158 | 158 | changesets = @repository.latest_changesets('README', nil) |
|
159 | 159 | assert_equal %w|31 30 28 17 8 6 1 0|, changesets.collect(&:revision) |
|
160 | 160 | |
|
161 | 161 | changesets = @repository.latest_changesets('README','8') |
|
162 | 162 | assert_equal %w|8 6 1 0|, changesets.collect(&:revision) |
|
163 | 163 | |
|
164 | 164 | changesets = @repository.latest_changesets('README','8', 2) |
|
165 | 165 | assert_equal %w|8 6|, changesets.collect(&:revision) |
|
166 | 166 | |
|
167 | 167 | # with_dirpath |
|
168 | 168 | changesets = @repository.latest_changesets('images', nil) |
|
169 | 169 | assert_equal %w|1 0|, changesets.collect(&:revision) |
|
170 | 170 | |
|
171 | 171 | path = 'sql_escape/percent%dir' |
|
172 | 172 | changesets = @repository.latest_changesets(path, nil) |
|
173 | 173 | assert_equal %w|30 13 11 10 9|, changesets.collect(&:revision) |
|
174 | 174 | |
|
175 | 175 | changesets = @repository.latest_changesets(path, '11') |
|
176 | 176 | assert_equal %w|11 10 9|, changesets.collect(&:revision) |
|
177 | 177 | |
|
178 | 178 | changesets = @repository.latest_changesets(path, '11', 2) |
|
179 | 179 | assert_equal %w|11 10|, changesets.collect(&:revision) |
|
180 | 180 | |
|
181 | 181 | path = 'sql_escape/underscore_dir' |
|
182 | 182 | changesets = @repository.latest_changesets(path, nil) |
|
183 | 183 | assert_equal %w|30 13 12 9|, changesets.collect(&:revision) |
|
184 | 184 | |
|
185 | 185 | changesets = @repository.latest_changesets(path, '12') |
|
186 | 186 | assert_equal %w|12 9|, changesets.collect(&:revision) |
|
187 | 187 | |
|
188 | 188 | changesets = @repository.latest_changesets(path, '12', 1) |
|
189 | 189 | assert_equal %w|12|, changesets.collect(&:revision) |
|
190 | end | |
|
191 | ||
|
192 | def test_latest_changesets_tag | |
|
193 | assert_equal 0, @repository.changesets.count | |
|
194 | @repository.fetch_changesets | |
|
195 | @project.reload | |
|
196 | assert_equal NUM_REV, @repository.changesets.count | |
|
190 | 197 | |
|
191 | # tag | |
|
192 | 198 | changesets = @repository.latest_changesets('', 'tag_test.00') |
|
193 | 199 | assert_equal %w|5 4 3 2 1 0|, changesets.collect(&:revision) |
|
194 | 200 | |
|
195 | 201 | changesets = @repository.latest_changesets('', 'tag_test.00', 2) |
|
196 | 202 | assert_equal %w|5 4|, changesets.collect(&:revision) |
|
197 | 203 | |
|
198 | 204 | changesets = @repository.latest_changesets('sources', 'tag_test.00') |
|
199 | 205 | assert_equal %w|4 3 2 1 0|, changesets.collect(&:revision) |
|
200 | 206 | |
|
201 | 207 | changesets = @repository.latest_changesets('sources', 'tag_test.00', 2) |
|
202 | 208 | assert_equal %w|4 3|, changesets.collect(&:revision) |
|
209 | end | |
|
210 | ||
|
211 | def test_latest_changesets_branch | |
|
212 | assert_equal 0, @repository.changesets.count | |
|
213 | @repository.fetch_changesets | |
|
214 | @project.reload | |
|
215 | assert_equal NUM_REV, @repository.changesets.count | |
|
203 | 216 | |
|
204 | # named branch | |
|
205 | 217 | if @repository.scm.class.client_version_above?([1, 6]) |
|
206 | 218 | changesets = @repository.latest_changesets('', @branch_char_1) |
|
207 | 219 | assert_equal %w|27 26|, changesets.collect(&:revision) |
|
208 | 220 | end |
|
209 | 221 | |
|
210 | 222 | changesets = @repository.latest_changesets("latin-1-dir/test-#{@char_1}-subdir", @branch_char_1) |
|
211 | 223 | assert_equal %w|27|, changesets.collect(&:revision) |
|
212 | 224 | end |
|
213 | 225 | |
|
214 | 226 | def test_copied_files |
|
215 | 227 | assert_equal 0, @repository.changesets.count |
|
216 | 228 | @repository.fetch_changesets |
|
217 | 229 | @project.reload |
|
218 | 230 | assert_equal NUM_REV, @repository.changesets.count |
|
219 | 231 | |
|
220 | 232 | cs1 = @repository.changesets.find_by_revision('13') |
|
221 | 233 | assert_not_nil cs1 |
|
222 | 234 | c1 = cs1.filechanges.sort_by(&:path) |
|
223 | 235 | assert_equal 2, c1.size |
|
224 | 236 | |
|
225 | 237 | assert_equal 'A', c1[0].action |
|
226 | 238 | assert_equal '/sql_escape/percent%dir/percentfile1.txt', c1[0].path |
|
227 | 239 | assert_equal '/sql_escape/percent%dir/percent%file1.txt', c1[0].from_path |
|
228 | 240 | assert_equal '3a330eb32958', c1[0].from_revision |
|
229 | 241 | |
|
230 | 242 | assert_equal 'A', c1[1].action |
|
231 | 243 | assert_equal '/sql_escape/underscore_dir/understrike-file.txt', c1[1].path |
|
232 | 244 | assert_equal '/sql_escape/underscore_dir/understrike_file.txt', c1[1].from_path |
|
233 | 245 | |
|
234 | 246 | cs2 = @repository.changesets.find_by_revision('15') |
|
235 | 247 | c2 = cs2.filechanges |
|
236 | 248 | assert_equal 1, c2.size |
|
237 | 249 | |
|
238 | 250 | assert_equal 'A', c2[0].action |
|
239 | 251 | assert_equal '/README (1)[2]&,%.-3_4', c2[0].path |
|
240 | 252 | assert_equal '/README', c2[0].from_path |
|
241 | 253 | assert_equal '933ca60293d7', c2[0].from_revision |
|
242 | 254 | |
|
243 | 255 | cs3 = @repository.changesets.find_by_revision('19') |
|
244 | 256 | c3 = cs3.filechanges |
|
245 | 257 | assert_equal 1, c3.size |
|
246 | 258 | assert_equal 'A', c3[0].action |
|
247 | 259 | assert_equal "/latin-1-dir/test-#{@char_1}-1.txt", c3[0].path |
|
248 | 260 | assert_equal "/latin-1-dir/test-#{@char_1}.txt", c3[0].from_path |
|
249 | 261 | assert_equal '5d9891a1b425', c3[0].from_revision |
|
250 | 262 | end |
|
251 | 263 | |
|
252 | 264 | def test_find_changeset_by_name |
|
253 | 265 | assert_equal 0, @repository.changesets.count |
|
254 | 266 | @repository.fetch_changesets |
|
255 | 267 | @project.reload |
|
256 | 268 | assert_equal NUM_REV, @repository.changesets.count |
|
257 | 269 | %w|2 400bb8672109 400|.each do |r| |
|
258 | 270 | assert_equal '2', @repository.find_changeset_by_name(r).revision |
|
259 | 271 | end |
|
260 | 272 | end |
|
261 | 273 | |
|
262 | 274 | def test_find_changeset_by_invalid_name |
|
263 | 275 | assert_equal 0, @repository.changesets.count |
|
264 | 276 | @repository.fetch_changesets |
|
265 | 277 | @project.reload |
|
266 | 278 | assert_equal NUM_REV, @repository.changesets.count |
|
267 | 279 | assert_nil @repository.find_changeset_by_name('100000') |
|
268 | 280 | end |
|
269 | 281 | |
|
270 | 282 | def test_identifier |
|
271 | 283 | assert_equal 0, @repository.changesets.count |
|
272 | 284 | @repository.fetch_changesets |
|
273 | 285 | @project.reload |
|
274 | 286 | assert_equal NUM_REV, @repository.changesets.count |
|
275 | 287 | c = @repository.changesets.find_by_revision('2') |
|
276 | 288 | assert_equal c.scmid, c.identifier |
|
277 | 289 | end |
|
278 | 290 | |
|
279 | 291 | def test_format_identifier |
|
280 | 292 | assert_equal 0, @repository.changesets.count |
|
281 | 293 | @repository.fetch_changesets |
|
282 | 294 | @project.reload |
|
283 | 295 | assert_equal NUM_REV, @repository.changesets.count |
|
284 | 296 | c = @repository.changesets.find_by_revision('2') |
|
285 | 297 | assert_equal '2:400bb8672109', c.format_identifier |
|
286 | 298 | end |
|
287 | 299 | |
|
288 | 300 | def test_find_changeset_by_empty_name |
|
289 | 301 | assert_equal 0, @repository.changesets.count |
|
290 | 302 | @repository.fetch_changesets |
|
291 | 303 | @project.reload |
|
292 | 304 | assert_equal NUM_REV, @repository.changesets.count |
|
293 | 305 | ['', ' ', nil].each do |r| |
|
294 | 306 | assert_nil @repository.find_changeset_by_name(r) |
|
295 | 307 | end |
|
296 | 308 | end |
|
297 | 309 | |
|
298 | 310 | def test_parents |
|
299 | 311 | assert_equal 0, @repository.changesets.count |
|
300 | 312 | @repository.fetch_changesets |
|
301 | 313 | @project.reload |
|
302 | 314 | assert_equal NUM_REV, @repository.changesets.count |
|
303 | 315 | r1 = @repository.changesets.find_by_revision('0') |
|
304 | 316 | assert_equal [], r1.parents |
|
305 | 317 | r2 = @repository.changesets.find_by_revision('1') |
|
306 | 318 | assert_equal 1, r2.parents.length |
|
307 | 319 | assert_equal "0885933ad4f6", |
|
308 | 320 | r2.parents[0].identifier |
|
309 | 321 | r3 = @repository.changesets.find_by_revision('30') |
|
310 | 322 | assert_equal 2, r3.parents.length |
|
311 | 323 | r4 = [r3.parents[0].identifier, r3.parents[1].identifier].sort |
|
312 | 324 | assert_equal "3a330eb32958", r4[0] |
|
313 | 325 | assert_equal "a94b0528f24f", r4[1] |
|
314 | 326 | end |
|
315 | 327 | |
|
316 | 328 | def test_activities |
|
317 | 329 | c = Changeset.new(:repository => @repository, |
|
318 | 330 | :committed_on => Time.now, |
|
319 | 331 | :revision => '123', |
|
320 | 332 | :scmid => 'abc400bb8672', |
|
321 | 333 | :comments => 'test') |
|
322 | 334 | assert c.event_title.include?('123:abc400bb8672:') |
|
323 | 335 | assert_equal 'abc400bb8672', c.event_url[:rev] |
|
324 | 336 | end |
|
325 | 337 | |
|
326 | 338 | def test_previous |
|
327 | 339 | assert_equal 0, @repository.changesets.count |
|
328 | 340 | @repository.fetch_changesets |
|
329 | 341 | @project.reload |
|
330 | 342 | assert_equal NUM_REV, @repository.changesets.count |
|
331 | 343 | %w|28 3ae45e2d177d 3ae45|.each do |r1| |
|
332 | 344 | changeset = @repository.find_changeset_by_name(r1) |
|
333 | 345 | %w|27 7bbf4c738e71 7bbf|.each do |r2| |
|
334 | 346 | assert_equal @repository.find_changeset_by_name(r2), changeset.previous |
|
335 | 347 | end |
|
336 | 348 | end |
|
337 | 349 | end |
|
338 | 350 | |
|
339 | 351 | def test_previous_nil |
|
340 | 352 | assert_equal 0, @repository.changesets.count |
|
341 | 353 | @repository.fetch_changesets |
|
342 | 354 | @project.reload |
|
343 | 355 | assert_equal NUM_REV, @repository.changesets.count |
|
344 | 356 | %w|0 0885933ad4f6 0885|.each do |r1| |
|
345 | 357 | changeset = @repository.find_changeset_by_name(r1) |
|
346 | 358 | assert_nil changeset.previous |
|
347 | 359 | end |
|
348 | 360 | end |
|
349 | 361 | |
|
350 | 362 | def test_next |
|
351 | 363 | assert_equal 0, @repository.changesets.count |
|
352 | 364 | @repository.fetch_changesets |
|
353 | 365 | @project.reload |
|
354 | 366 | assert_equal NUM_REV, @repository.changesets.count |
|
355 | 367 | %w|27 7bbf4c738e71 7bbf|.each do |r2| |
|
356 | 368 | changeset = @repository.find_changeset_by_name(r2) |
|
357 | 369 | %w|28 3ae45e2d177d 3ae45|.each do |r1| |
|
358 | 370 | assert_equal @repository.find_changeset_by_name(r1), changeset.next |
|
359 | 371 | end |
|
360 | 372 | end |
|
361 | 373 | end |
|
362 | 374 | |
|
363 | 375 | def test_next_nil |
|
364 | 376 | assert_equal 0, @repository.changesets.count |
|
365 | 377 | @repository.fetch_changesets |
|
366 | 378 | @project.reload |
|
367 | 379 | assert_equal NUM_REV, @repository.changesets.count |
|
368 | 380 | %w|31 31eeee7395c8 31eee|.each do |r1| |
|
369 | 381 | changeset = @repository.find_changeset_by_name(r1) |
|
370 | 382 | assert_nil changeset.next |
|
371 | 383 | end |
|
372 | 384 | end |
|
373 | 385 | else |
|
374 | 386 | puts "Mercurial test repository NOT FOUND. Skipping unit tests !!!" |
|
375 | 387 | def test_fake; assert true end |
|
376 | 388 | end |
|
377 | 389 | end |
General Comments 0
You need to be logged in to leave comments.
Login now