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