comparison test/unit/repository_git_test.rb @ 441:cbce1fd3b1b7 redmine-1.2

Update to Redmine 1.2-stable branch (Redmine SVN rev 6000)
author Chris Cannam
date Mon, 06 Jun 2011 14:24:13 +0100
parents 051f544170fe
children cbb26bc654de
comparison
equal deleted inserted replaced
245:051f544170fe 441:cbce1fd3b1b7
1 # redMine - project management software 1 # Redmine - project management software
2 # Copyright (C) 2006-2007 Jean-Philippe Lang 2 # Copyright (C) 2006-2011 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__)
23 # No '..' in the repository path 23 # No '..' in the repository path
24 REPOSITORY_PATH = RAILS_ROOT.gsub(%r{config\/\.\.}, '') + '/tmp/test/git_repository' 24 REPOSITORY_PATH = RAILS_ROOT.gsub(%r{config\/\.\.}, '') + '/tmp/test/git_repository'
25 REPOSITORY_PATH.gsub!(/\//, "\\") if Redmine::Platform.mswin? 25 REPOSITORY_PATH.gsub!(/\//, "\\") if Redmine::Platform.mswin?
26 26
27 FELIX_HEX = "Felix Sch\xC3\xA4fer" 27 FELIX_HEX = "Felix Sch\xC3\xA4fer"
28 28 CHAR_1_HEX = "\xc3\x9c"
29 def setup 29
30 Setting.commit_logs_encoding = 'UTF-8' 30 ## Ruby uses ANSI api to fork a process on Windows.
31 @project = Project.find(3) 31 ## Japanese Shift_JIS and Traditional Chinese Big5 have 0x5c(backslash) problem
32 @repository = Repository::Git.create(:project => @project, :url => REPOSITORY_PATH) 32 ## and these are incompatible with ASCII.
33 assert @repository 33 # WINDOWS_PASS = Redmine::Platform.mswin?
34 end 34 WINDOWS_PASS = false
35 35
36 if File.directory?(REPOSITORY_PATH) 36 if File.directory?(REPOSITORY_PATH)
37 def setup
38 klass = Repository::Git
39 assert_equal "Git", klass.scm_name
40 assert klass.scm_adapter_class
41 assert_not_equal "", klass.scm_command
42 assert_equal true, klass.scm_available
43
44 @project = Project.find(3)
45 @repository = Repository::Git.create(
46 :project => @project,
47 :url => REPOSITORY_PATH,
48 :path_encoding => 'ISO-8859-1'
49 )
50 assert @repository
51 @char_1 = CHAR_1_HEX.dup
52 if @char_1.respond_to?(:force_encoding)
53 @char_1.force_encoding('UTF-8')
54 end
55 end
56
37 def test_fetch_changesets_from_scratch 57 def test_fetch_changesets_from_scratch
38 @repository.fetch_changesets 58 assert_nil @repository.extra_info
39 @repository.reload 59
40 60 @repository.fetch_changesets
41 assert_equal 16, @repository.changesets.count 61 @repository.reload
42 assert_equal 25, @repository.changes.count 62
63 assert_equal 21, @repository.changesets.count
64 assert_equal 33, @repository.changes.count
43 65
44 commit = @repository.changesets.find(:first, :order => 'committed_on ASC') 66 commit = @repository.changesets.find(:first, :order => 'committed_on ASC')
45 assert_equal "Initial import.\nThe repository contains 3 files.", commit.comments 67 assert_equal "Initial import.\nThe repository contains 3 files.", commit.comments
46 assert_equal "jsmith <jsmith@foo.bar>", commit.committer 68 assert_equal "jsmith <jsmith@foo.bar>", commit.committer
47 assert_equal User.find_by_login('jsmith'), commit.user 69 assert_equal User.find_by_login('jsmith'), commit.user
52 assert_equal "7234cb2750b63f47bff735edc50a1c0a433c2518", commit.scmid 74 assert_equal "7234cb2750b63f47bff735edc50a1c0a433c2518", commit.scmid
53 assert_equal 3, commit.changes.count 75 assert_equal 3, commit.changes.count
54 change = commit.changes.sort_by(&:path).first 76 change = commit.changes.sort_by(&:path).first
55 assert_equal "README", change.path 77 assert_equal "README", change.path
56 assert_equal "A", change.action 78 assert_equal "A", change.action
57 end 79
58 80 assert_equal 4, @repository.extra_info["branches"].size
81 end
82
59 def test_fetch_changesets_incremental 83 def test_fetch_changesets_incremental
60 @repository.fetch_changesets 84 @repository.fetch_changesets
61 # Remove the 3 latest changesets 85 @repository.reload
62 @repository.changesets.find(:all, :order => 'committed_on DESC', :limit => 3).each(&:destroy) 86 assert_equal 21, @repository.changesets.count
87 assert_equal 33, @repository.changes.count
88 extra_info_db = @repository.extra_info["branches"]
89 assert_equal 4, extra_info_db.size
90 assert_equal "1ca7f5ed374f3cb31a93ae5215c2e25cc6ec5127",
91 extra_info_db["latin-1-path-encoding"]["last_scmid"]
92 assert_equal "83ca5fd546063a3c7dc2e568ba3355661a9e2b2c",
93 extra_info_db["master"]["last_scmid"]
94
95 del_revs = [
96 "83ca5fd546063a3c7dc2e568ba3355661a9e2b2c",
97 "ed5bb786bbda2dee66a2d50faf51429dbc043a7b",
98 "4f26664364207fa8b1af9f8722647ab2d4ac5d43",
99 "deff712f05a90d96edbd70facc47d944be5897e3",
100 "32ae898b720c2f7eec2723d5bdd558b4cb2d3ddf",
101 "7e61ac704deecde634b51e59daa8110435dcb3da",
102 ]
103 @repository.changesets.each do |rev|
104 rev.destroy if del_revs.detect {|r| r == rev.scmid.to_s }
105 end
63 @repository.reload 106 @repository.reload
64 cs1 = @repository.changesets 107 cs1 = @repository.changesets
65 assert_equal 13, cs1.count 108 assert_equal 15, cs1.count
66 109 h = @repository.extra_info.dup
67 rev_a_commit = @repository.changesets.find(:first, :order => 'committed_on DESC') 110 h["branches"]["master"]["last_scmid"] =
68 assert_equal '4f26664364207fa8b1af9f8722647ab2d4ac5d43', rev_a_commit.revision 111 "4a07fe31bffcf2888791f3e6cbc9c4545cefe3e8"
69 # Mon Jul 5 22:34:26 2010 +0200 112 @repository.merge_extra_info(h)
70 rev_a_committed_on = Time.gm(2010, 7, 5, 20, 34, 26) 113 @repository.save
71 assert_equal '4f26664364207fa8b1af9f8722647ab2d4ac5d43', rev_a_commit.scmid 114 @repository.reload
72 assert_equal rev_a_committed_on, rev_a_commit.committed_on 115 extra_info_db_1 = @repository.extra_info["branches"]
73 latest_rev = @repository.latest_changeset 116 assert_equal "4a07fe31bffcf2888791f3e6cbc9c4545cefe3e8",
74 assert_equal rev_a_committed_on, latest_rev.committed_on 117 extra_info_db_1["master"]["last_scmid"]
75 118
76 @repository.fetch_changesets 119 @repository.fetch_changesets
77 assert_equal 16, @repository.changesets.count 120 assert_equal 21, @repository.changesets.count
121 end
122
123 def test_fetch_changesets_invalid_rev
124 @repository.fetch_changesets
125 @repository.reload
126 assert_equal 21, @repository.changesets.count
127 assert_equal 33, @repository.changes.count
128 extra_info_db = @repository.extra_info["branches"]
129 assert_equal 4, extra_info_db.size
130 assert_equal "1ca7f5ed374f3cb31a93ae5215c2e25cc6ec5127",
131 extra_info_db["latin-1-path-encoding"]["last_scmid"]
132 assert_equal "83ca5fd546063a3c7dc2e568ba3355661a9e2b2c",
133 extra_info_db["master"]["last_scmid"]
134
135 del_revs = [
136 "83ca5fd546063a3c7dc2e568ba3355661a9e2b2c",
137 "ed5bb786bbda2dee66a2d50faf51429dbc043a7b",
138 "4f26664364207fa8b1af9f8722647ab2d4ac5d43",
139 "deff712f05a90d96edbd70facc47d944be5897e3",
140 "32ae898b720c2f7eec2723d5bdd558b4cb2d3ddf",
141 "7e61ac704deecde634b51e59daa8110435dcb3da",
142 ]
143 @repository.changesets.each do |rev|
144 rev.destroy if del_revs.detect {|r| r == rev.scmid.to_s }
145 end
146 @repository.reload
147 cs1 = @repository.changesets
148 assert_equal 15, cs1.count
149 h = @repository.extra_info.dup
150 h["branches"]["master"]["last_scmid"] =
151 "abcd1234efgh"
152 @repository.merge_extra_info(h)
153 @repository.save
154 @repository.reload
155 extra_info_db_1 = @repository.extra_info["branches"]
156 assert_equal "abcd1234efgh",
157 extra_info_db_1["master"]["last_scmid"]
158
159 @repository.fetch_changesets
160 assert_equal 15, @repository.changesets.count
161 end
162
163 def test_db_consistent_ordering_init
164 assert_nil @repository.extra_info
165 @repository.fetch_changesets
166 @repository.reload
167 assert_equal 1, @repository.extra_info["db_consistent"]["ordering"]
168 end
169
170 def test_db_consistent_ordering_before_1_2
171 assert_nil @repository.extra_info
172 @repository.fetch_changesets
173 @repository.reload
174 assert_equal 21, @repository.changesets.count
175 assert_not_nil @repository.extra_info
176 @repository.write_attribute(:extra_info, nil)
177 @repository.save
178 assert_nil @repository.extra_info
179 assert_equal 21, @repository.changesets.count
180 @repository.fetch_changesets
181 @repository.reload
182 assert_equal 0, @repository.extra_info["db_consistent"]["ordering"]
183
184 del_revs = [
185 "83ca5fd546063a3c7dc2e568ba3355661a9e2b2c",
186 "ed5bb786bbda2dee66a2d50faf51429dbc043a7b",
187 "4f26664364207fa8b1af9f8722647ab2d4ac5d43",
188 "deff712f05a90d96edbd70facc47d944be5897e3",
189 "32ae898b720c2f7eec2723d5bdd558b4cb2d3ddf",
190 "7e61ac704deecde634b51e59daa8110435dcb3da",
191 ]
192 @repository.changesets.each do |rev|
193 rev.destroy if del_revs.detect {|r| r == rev.scmid.to_s }
194 end
195 @repository.reload
196 cs1 = @repository.changesets
197 assert_equal 15, cs1.count
198 assert_equal 0, @repository.extra_info["db_consistent"]["ordering"]
199 h = @repository.extra_info.dup
200 h["branches"]["master"]["last_scmid"] =
201 "4a07fe31bffcf2888791f3e6cbc9c4545cefe3e8"
202 @repository.merge_extra_info(h)
203 @repository.save
204 @repository.reload
205 extra_info_db_1 = @repository.extra_info["branches"]
206 assert_equal "4a07fe31bffcf2888791f3e6cbc9c4545cefe3e8",
207 extra_info_db_1["master"]["last_scmid"]
208
209 @repository.fetch_changesets
210 assert_equal 21, @repository.changesets.count
211 assert_equal 0, @repository.extra_info["db_consistent"]["ordering"]
212 end
213
214 def test_latest_changesets
215 @repository.fetch_changesets
216 @repository.reload
217 # with limit
218 changesets = @repository.latest_changesets('', nil, 2)
219 assert_equal 2, changesets.size
220
221 # with path
222 changesets = @repository.latest_changesets('images', nil)
223 assert_equal [
224 'deff712f05a90d96edbd70facc47d944be5897e3',
225 '899a15dba03a3b350b89c3f537e4bbe02a03cdc9',
226 '7234cb2750b63f47bff735edc50a1c0a433c2518',
227 ], changesets.collect(&:revision)
228
229 changesets = @repository.latest_changesets('README', nil)
230 assert_equal [
231 '32ae898b720c2f7eec2723d5bdd558b4cb2d3ddf',
232 '4a07fe31bffcf2888791f3e6cbc9c4545cefe3e8',
233 '713f4944648826f558cf548222f813dabe7cbb04',
234 '61b685fbe55ab05b5ac68402d5720c1a6ac973d1',
235 '899a15dba03a3b350b89c3f537e4bbe02a03cdc9',
236 '7234cb2750b63f47bff735edc50a1c0a433c2518',
237 ], changesets.collect(&:revision)
238
239 # with path, revision and limit
240 changesets = @repository.latest_changesets('images', '899a15dba')
241 assert_equal [
242 '899a15dba03a3b350b89c3f537e4bbe02a03cdc9',
243 '7234cb2750b63f47bff735edc50a1c0a433c2518',
244 ], changesets.collect(&:revision)
245
246 changesets = @repository.latest_changesets('images', '899a15dba', 1)
247 assert_equal [
248 '899a15dba03a3b350b89c3f537e4bbe02a03cdc9',
249 ], changesets.collect(&:revision)
250
251 changesets = @repository.latest_changesets('README', '899a15dba')
252 assert_equal [
253 '899a15dba03a3b350b89c3f537e4bbe02a03cdc9',
254 '7234cb2750b63f47bff735edc50a1c0a433c2518',
255 ], changesets.collect(&:revision)
256
257 changesets = @repository.latest_changesets('README', '899a15dba', 1)
258 assert_equal [
259 '899a15dba03a3b350b89c3f537e4bbe02a03cdc9',
260 ], changesets.collect(&:revision)
261
262 # with path, tag and limit
263 changesets = @repository.latest_changesets('images', 'tag01.annotated')
264 assert_equal [
265 '899a15dba03a3b350b89c3f537e4bbe02a03cdc9',
266 '7234cb2750b63f47bff735edc50a1c0a433c2518',
267 ], changesets.collect(&:revision)
268
269 changesets = @repository.latest_changesets('images', 'tag01.annotated', 1)
270 assert_equal [
271 '899a15dba03a3b350b89c3f537e4bbe02a03cdc9',
272 ], changesets.collect(&:revision)
273
274 changesets = @repository.latest_changesets('README', 'tag01.annotated')
275 assert_equal [
276 '899a15dba03a3b350b89c3f537e4bbe02a03cdc9',
277 '7234cb2750b63f47bff735edc50a1c0a433c2518',
278 ], changesets.collect(&:revision)
279
280 changesets = @repository.latest_changesets('README', 'tag01.annotated', 1)
281 assert_equal [
282 '899a15dba03a3b350b89c3f537e4bbe02a03cdc9',
283 ], changesets.collect(&:revision)
284
285 # with path, branch and limit
286 changesets = @repository.latest_changesets('images', 'test_branch')
287 assert_equal [
288 '899a15dba03a3b350b89c3f537e4bbe02a03cdc9',
289 '7234cb2750b63f47bff735edc50a1c0a433c2518',
290 ], changesets.collect(&:revision)
291
292 changesets = @repository.latest_changesets('images', 'test_branch', 1)
293 assert_equal [
294 '899a15dba03a3b350b89c3f537e4bbe02a03cdc9',
295 ], changesets.collect(&:revision)
296
297 changesets = @repository.latest_changesets('README', 'test_branch')
298 assert_equal [
299 '713f4944648826f558cf548222f813dabe7cbb04',
300 '61b685fbe55ab05b5ac68402d5720c1a6ac973d1',
301 '899a15dba03a3b350b89c3f537e4bbe02a03cdc9',
302 '7234cb2750b63f47bff735edc50a1c0a433c2518',
303 ], changesets.collect(&:revision)
304
305 changesets = @repository.latest_changesets('README', 'test_branch', 2)
306 assert_equal [
307 '713f4944648826f558cf548222f813dabe7cbb04',
308 '61b685fbe55ab05b5ac68402d5720c1a6ac973d1',
309 ], changesets.collect(&:revision)
310
311 # latin-1 encoding path
312 changesets = @repository.latest_changesets(
313 "latin-1-dir/test-#{@char_1}-2.txt", '64f1f3e89')
314 assert_equal [
315 '64f1f3e89ad1cb57976ff0ad99a107012ba3481d',
316 '4fc55c43bf3d3dc2efb66145365ddc17639ce81e',
317 ], changesets.collect(&:revision)
318
319 changesets = @repository.latest_changesets(
320 "latin-1-dir/test-#{@char_1}-2.txt", '64f1f3e89', 1)
321 assert_equal [
322 '64f1f3e89ad1cb57976ff0ad99a107012ba3481d',
323 ], changesets.collect(&:revision)
324 end
325
326 def test_latest_changesets_latin_1_dir
327 if WINDOWS_PASS
328 #
329 else
330 @repository.fetch_changesets
331 @repository.reload
332 changesets = @repository.latest_changesets(
333 "latin-1-dir/test-#{@char_1}-subdir", '1ca7f5ed')
334 assert_equal [
335 '1ca7f5ed374f3cb31a93ae5215c2e25cc6ec5127',
336 ], changesets.collect(&:revision)
337 end
78 end 338 end
79 339
80 def test_find_changeset_by_name 340 def test_find_changeset_by_name
81 @repository.fetch_changesets 341 @repository.fetch_changesets
82 @repository.reload 342 @repository.reload
95 end 355 end
96 356
97 def test_identifier 357 def test_identifier
98 @repository.fetch_changesets 358 @repository.fetch_changesets
99 @repository.reload 359 @repository.reload
100 c = @repository.changesets.find_by_revision('7234cb2750b63f47bff735edc50a1c0a433c2518') 360 c = @repository.changesets.find_by_revision(
361 '7234cb2750b63f47bff735edc50a1c0a433c2518')
101 assert_equal c.scmid, c.identifier 362 assert_equal c.scmid, c.identifier
102 end 363 end
103 364
104 def test_format_identifier 365 def test_format_identifier
105 @repository.fetch_changesets 366 @repository.fetch_changesets
106 @repository.reload 367 @repository.reload
107 c = @repository.changesets.find_by_revision('7234cb2750b63f47bff735edc50a1c0a433c2518') 368 c = @repository.changesets.find_by_revision(
369 '7234cb2750b63f47bff735edc50a1c0a433c2518')
108 assert_equal '7234cb27', c.format_identifier 370 assert_equal '7234cb27', c.format_identifier
109 end 371 end
110 372
111 def test_activities 373 def test_activities
112 c = Changeset.new(:repository => @repository, 374 c = Changeset.new(:repository => @repository,
119 end 381 end
120 382
121 def test_log_utf8 383 def test_log_utf8
122 @repository.fetch_changesets 384 @repository.fetch_changesets
123 @repository.reload 385 @repository.reload
124 str_felix_hex = FELIX_HEX 386 str_felix_hex = FELIX_HEX.dup
125 if str_felix_hex.respond_to?(:force_encoding) 387 if str_felix_hex.respond_to?(:force_encoding)
126 str_felix_hex.force_encoding('UTF-8') 388 str_felix_hex.force_encoding('UTF-8')
127 end 389 end
128 c = @repository.changesets.find_by_revision('ed5bb786bbda2dee66a2d50faf51429dbc043a7b') 390 c = @repository.changesets.find_by_revision(
391 'ed5bb786bbda2dee66a2d50faf51429dbc043a7b')
129 assert_equal "#{str_felix_hex} <felix@fachschaften.org>", c.committer 392 assert_equal "#{str_felix_hex} <felix@fachschaften.org>", c.committer
393 end
394
395 def test_previous
396 @repository.fetch_changesets
397 @repository.reload
398 %w|1ca7f5ed374f3cb31a93ae5215c2e25cc6ec5127 1ca7f5ed|.each do |r1|
399 changeset = @repository.find_changeset_by_name(r1)
400 %w|64f1f3e89ad1cb57976ff0ad99a107012ba3481d 64f1f3e89ad1|.each do |r2|
401 assert_equal @repository.find_changeset_by_name(r2), changeset.previous
402 end
403 end
404 end
405
406 def test_previous_nil
407 @repository.fetch_changesets
408 @repository.reload
409 %w|7234cb2750b63f47bff735edc50a1c0a433c2518 7234cb2|.each do |r1|
410 changeset = @repository.find_changeset_by_name(r1)
411 assert_nil changeset.previous
412 end
413 end
414
415 def test_next
416 @repository.fetch_changesets
417 @repository.reload
418 %w|64f1f3e89ad1cb57976ff0ad99a107012ba3481d 64f1f3e89ad1|.each do |r2|
419 changeset = @repository.find_changeset_by_name(r2)
420 %w|1ca7f5ed374f3cb31a93ae5215c2e25cc6ec5127 1ca7f5ed|.each do |r1|
421 assert_equal @repository.find_changeset_by_name(r1), changeset.next
422 end
423 end
424 end
425
426 def test_next_nil
427 @repository.fetch_changesets
428 @repository.reload
429 %w|67e7792ce20ccae2e4bb73eed09bb397819c8834 67e7792ce20cca|.each do |r1|
430 changeset = @repository.find_changeset_by_name(r1)
431 assert_nil changeset.next
432 end
130 end 433 end
131 else 434 else
132 puts "Git test repository NOT FOUND. Skipping unit tests !!!" 435 puts "Git test repository NOT FOUND. Skipping unit tests !!!"
133 def test_fake; assert true end 436 def test_fake; assert true end
134 end 437 end