@@ -122,9 +122,15 class Repository::Mercurial < Repository | |||||
122 | all |
|
122 | all | |
123 | end |
|
123 | end | |
124 |
|
124 | |||
|
125 | def is_short_id_in_db? | |||
|
126 | return @is_short_id_in_db unless @is_short_id_in_db.nil? | |||
|
127 | cs = changesets.first | |||
|
128 | @is_short_id_in_db = (!cs.nil? && cs.scmid.length != 40) | |||
|
129 | end | |||
|
130 | private :is_short_id_in_db? | |||
|
131 | ||||
125 | def scmid_for_inserting_db(scmid) |
|
132 | def scmid_for_inserting_db(scmid) | |
126 | # TODO: switch short or long by existing value in DB |
|
133 | is_short_id_in_db? ? scmid[0, 12] : scmid | |
127 | scmid[0, 12] |
|
|||
128 | end |
|
134 | end | |
129 |
|
135 | |||
130 | def nodes_in_branch(rev, branch_limit) |
|
136 | def nodes_in_branch(rev, branch_limit) |
@@ -104,12 +104,22 class RepositoryMercurialTest < ActiveSupport::TestCase | |||||
104 |
|
104 | |||
105 | def test_entries_short_id |
|
105 | def test_entries_short_id | |
106 | assert_equal 0, @repository.changesets.count |
|
106 | assert_equal 0, @repository.changesets.count | |
|
107 | create_rev0_short_id | |||
|
108 | assert_equal 1, @repository.changesets.count | |||
107 | @repository.fetch_changesets |
|
109 | @repository.fetch_changesets | |
108 | @project.reload |
|
110 | @project.reload | |
109 | assert_equal NUM_REV, @repository.changesets.count |
|
111 | assert_equal NUM_REV, @repository.changesets.count | |
110 | assert_entries(true) |
|
112 | assert_entries(true) | |
111 | end |
|
113 | end | |
112 |
|
114 | |||
|
115 | def test_entries_long_id | |||
|
116 | assert_equal 0, @repository.changesets.count | |||
|
117 | @repository.fetch_changesets | |||
|
118 | @project.reload | |||
|
119 | assert_equal NUM_REV, @repository.changesets.count | |||
|
120 | assert_entries(false) | |||
|
121 | end | |||
|
122 | ||||
113 | def test_entry_on_tip |
|
123 | def test_entry_on_tip | |
114 | entry = @repository.entry |
|
124 | entry = @repository.entry | |
115 | assert_kind_of Redmine::Scm::Adapters::Entry, entry |
|
125 | assert_kind_of Redmine::Scm::Adapters::Entry, entry | |
@@ -152,9 +162,16 class RepositoryMercurialTest < ActiveSupport::TestCase | |||||
152 | private :assert_entry |
|
162 | private :assert_entry | |
153 |
|
163 | |||
154 | def test_entry_short_id |
|
164 | def test_entry_short_id | |
|
165 | assert_equal 0, @repository.changesets.count | |||
|
166 | create_rev0_short_id | |||
|
167 | assert_equal 1, @repository.changesets.count | |||
155 | assert_entry(true) |
|
168 | assert_entry(true) | |
156 | end |
|
169 | end | |
157 |
|
170 | |||
|
171 | def test_entry_long_id | |||
|
172 | assert_entry(false) | |||
|
173 | end | |||
|
174 | ||||
158 | def test_fetch_changesets_from_scratch |
|
175 | def test_fetch_changesets_from_scratch | |
159 | assert_equal 0, @repository.changesets.count |
|
176 | assert_equal 0, @repository.changesets.count | |
160 | @repository.fetch_changesets |
|
177 | @repository.fetch_changesets | |
@@ -164,13 +181,39 class RepositoryMercurialTest < ActiveSupport::TestCase | |||||
164 | rev0 = @repository.changesets.find_by_revision('0') |
|
181 | rev0 = @repository.changesets.find_by_revision('0') | |
165 | assert_equal "Initial import.\nThe repository contains 3 files.", |
|
182 | assert_equal "Initial import.\nThe repository contains 3 files.", | |
166 | rev0.comments |
|
183 | rev0.comments | |
167 | assert_equal "0885933ad4f6", rev0.scmid |
|
184 | assert_equal "0885933ad4f68d77c2649cd11f8311276e7ef7ce", rev0.scmid | |
168 | first_rev = @repository.changesets.first |
|
185 | first_rev = @repository.changesets.first | |
169 | last_rev = @repository.changesets.last |
|
186 | last_rev = @repository.changesets.last | |
170 | assert_equal "#{NUM_REV - 1}", first_rev.revision |
|
187 | assert_equal "#{NUM_REV - 1}", first_rev.revision | |
171 | assert_equal "0", last_rev.revision |
|
188 | assert_equal "0", last_rev.revision | |
172 | end |
|
189 | end | |
173 |
|
190 | |||
|
191 | def test_fetch_changesets_keep_short_id | |||
|
192 | assert_equal 0, @repository.changesets.count | |||
|
193 | create_rev0_short_id | |||
|
194 | assert_equal 1, @repository.changesets.count | |||
|
195 | @repository.fetch_changesets | |||
|
196 | @project.reload | |||
|
197 | assert_equal NUM_REV, @repository.changesets.count | |||
|
198 | rev1 = @repository.changesets.find_by_revision('1') | |||
|
199 | assert_equal "9d5b5b004199", rev1.scmid | |||
|
200 | end | |||
|
201 | ||||
|
202 | def test_fetch_changesets_keep_long_id | |||
|
203 | assert_equal 0, @repository.changesets.count | |||
|
204 | Changeset.create!(:repository => @repository, | |||
|
205 | :committed_on => Time.now, | |||
|
206 | :revision => '0', | |||
|
207 | :scmid => '0885933ad4f68d77c2649cd11f8311276e7ef7ce', | |||
|
208 | :comments => 'test') | |||
|
209 | assert_equal 1, @repository.changesets.count | |||
|
210 | @repository.fetch_changesets | |||
|
211 | @project.reload | |||
|
212 | assert_equal NUM_REV, @repository.changesets.count | |||
|
213 | rev1 = @repository.changesets.find_by_revision('1') | |||
|
214 | assert_equal "9d5b5b00419901478496242e0768deba1ce8c51e", rev1.scmid | |||
|
215 | end | |||
|
216 | ||||
174 | def test_fetch_changesets_incremental |
|
217 | def test_fetch_changesets_incremental | |
175 | assert_equal 0, @repository.changesets.count |
|
218 | assert_equal 0, @repository.changesets.count | |
176 | @repository.fetch_changesets |
|
219 | @repository.fetch_changesets | |
@@ -279,6 +322,16 class RepositoryMercurialTest < ActiveSupport::TestCase | |||||
279 | assert_latest_changesets_tag |
|
322 | assert_latest_changesets_tag | |
280 | end |
|
323 | end | |
281 |
|
324 | |||
|
325 | def test_latest_changesets_tag_short_id | |||
|
326 | assert_equal 0, @repository.changesets.count | |||
|
327 | create_rev0_short_id | |||
|
328 | assert_equal 1, @repository.changesets.count | |||
|
329 | @repository.fetch_changesets | |||
|
330 | @project.reload | |||
|
331 | assert_equal NUM_REV, @repository.changesets.count | |||
|
332 | assert_latest_changesets_tag | |||
|
333 | end | |||
|
334 | ||||
282 | def test_latest_changesets_tag_with_path |
|
335 | def test_latest_changesets_tag_with_path | |
283 | assert_equal 0, @repository.changesets.count |
|
336 | assert_equal 0, @repository.changesets.count | |
284 | @repository.fetch_changesets |
|
337 | @repository.fetch_changesets | |
@@ -331,6 +384,16 class RepositoryMercurialTest < ActiveSupport::TestCase | |||||
331 | assert_latest_changesets_default_branch |
|
384 | assert_latest_changesets_default_branch | |
332 | end |
|
385 | end | |
333 |
|
386 | |||
|
387 | def test_latest_changesets_default_branch_short_id | |||
|
388 | assert_equal 0, @repository.changesets.count | |||
|
389 | create_rev0_short_id | |||
|
390 | assert_equal 1, @repository.changesets.count | |||
|
391 | @repository.fetch_changesets | |||
|
392 | @project.reload | |||
|
393 | assert_equal NUM_REV, @repository.changesets.count | |||
|
394 | assert_latest_changesets_default_branch | |||
|
395 | end | |||
|
396 | ||||
334 | def assert_copied_files(is_short_scmid=true) |
|
397 | def assert_copied_files(is_short_scmid=true) | |
335 | cs1 = @repository.changesets.find_by_revision('13') |
|
398 | cs1 = @repository.changesets.find_by_revision('13') | |
336 | assert_not_nil cs1 |
|
399 | assert_not_nil cs1 | |
@@ -374,12 +437,22 class RepositoryMercurialTest < ActiveSupport::TestCase | |||||
374 |
|
437 | |||
375 | def test_copied_files_short_id |
|
438 | def test_copied_files_short_id | |
376 | assert_equal 0, @repository.changesets.count |
|
439 | assert_equal 0, @repository.changesets.count | |
|
440 | create_rev0_short_id | |||
|
441 | assert_equal 1, @repository.changesets.count | |||
377 | @repository.fetch_changesets |
|
442 | @repository.fetch_changesets | |
378 | @project.reload |
|
443 | @project.reload | |
379 | assert_equal NUM_REV, @repository.changesets.count |
|
444 | assert_equal NUM_REV, @repository.changesets.count | |
380 | assert_copied_files(true) |
|
445 | assert_copied_files(true) | |
381 | end |
|
446 | end | |
382 |
|
447 | |||
|
448 | def test_copied_files_long_id | |||
|
449 | assert_equal 0, @repository.changesets.count | |||
|
450 | @repository.fetch_changesets | |||
|
451 | @project.reload | |||
|
452 | assert_equal NUM_REV, @repository.changesets.count | |||
|
453 | assert_copied_files(false) | |||
|
454 | end | |||
|
455 | ||||
383 | def test_find_changeset_by_name |
|
456 | def test_find_changeset_by_name | |
384 | assert_equal 0, @repository.changesets.count |
|
457 | assert_equal 0, @repository.changesets.count | |
385 | @repository.fetch_changesets |
|
458 | @repository.fetch_changesets | |
@@ -459,12 +532,22 class RepositoryMercurialTest < ActiveSupport::TestCase | |||||
459 |
|
532 | |||
460 | def test_parents_short_id |
|
533 | def test_parents_short_id | |
461 | assert_equal 0, @repository.changesets.count |
|
534 | assert_equal 0, @repository.changesets.count | |
|
535 | create_rev0_short_id | |||
|
536 | assert_equal 1, @repository.changesets.count | |||
462 | @repository.fetch_changesets |
|
537 | @repository.fetch_changesets | |
463 | @project.reload |
|
538 | @project.reload | |
464 | assert_equal NUM_REV, @repository.changesets.count |
|
539 | assert_equal NUM_REV, @repository.changesets.count | |
465 | assert_parents(true) |
|
540 | assert_parents(true) | |
466 | end |
|
541 | end | |
467 |
|
542 | |||
|
543 | def test_parents_long_id | |||
|
544 | assert_equal 0, @repository.changesets.count | |||
|
545 | @repository.fetch_changesets | |||
|
546 | @project.reload | |||
|
547 | assert_equal NUM_REV, @repository.changesets.count | |||
|
548 | assert_parents(false) | |||
|
549 | end | |||
|
550 | ||||
468 | def test_activities |
|
551 | def test_activities | |
469 | c = Changeset.new(:repository => @repository, |
|
552 | c = Changeset.new(:repository => @repository, | |
470 | :committed_on => Time.now, |
|
553 | :committed_on => Time.now, | |
@@ -523,6 +606,27 class RepositoryMercurialTest < ActiveSupport::TestCase | |||||
523 | end |
|
606 | end | |
524 | end |
|
607 | end | |
525 |
|
608 | |||
|
609 | def test_scmid_for_inserting_db_short_id | |||
|
610 | assert_equal 0, @repository.changesets.count | |||
|
611 | create_rev0_short_id | |||
|
612 | assert_equal 1, @repository.changesets.count | |||
|
613 | rev = "0123456789012345678901234567890123456789" | |||
|
614 | assert_equal 12, @repository.scmid_for_inserting_db(rev).length | |||
|
615 | end | |||
|
616 | ||||
|
617 | def test_scmid_for_inserting_db_long_id | |||
|
618 | rev = "0123456789012345678901234567890123456789" | |||
|
619 | assert_equal 0, @repository.changesets.count | |||
|
620 | assert_equal 40, @repository.scmid_for_inserting_db(rev).length | |||
|
621 | Changeset.create!(:repository => @repository, | |||
|
622 | :committed_on => Time.now, | |||
|
623 | :revision => '0', | |||
|
624 | :scmid => rev, | |||
|
625 | :comments => 'test') | |||
|
626 | assert_equal 1, @repository.changesets.count | |||
|
627 | assert_equal 40, @repository.scmid_for_inserting_db(rev).length | |||
|
628 | end | |||
|
629 | ||||
526 | def test_scmid_for_assert |
|
630 | def test_scmid_for_assert | |
527 | rev = "0123456789012345678901234567890123456789" |
|
631 | rev = "0123456789012345678901234567890123456789" | |
528 | assert_equal rev, scmid_for_assert(rev, false) |
|
632 | assert_equal rev, scmid_for_assert(rev, false) | |
@@ -534,6 +638,14 class RepositoryMercurialTest < ActiveSupport::TestCase | |||||
534 | def scmid_for_assert(hex, is_short=true) |
|
638 | def scmid_for_assert(hex, is_short=true) | |
535 | is_short ? hex[0, 12] : hex |
|
639 | is_short ? hex[0, 12] : hex | |
536 | end |
|
640 | end | |
|
641 | ||||
|
642 | def create_rev0_short_id | |||
|
643 | Changeset.create!(:repository => @repository, | |||
|
644 | :committed_on => Time.now, | |||
|
645 | :revision => '0', | |||
|
646 | :scmid => '0885933ad4f6', | |||
|
647 | :comments => 'test') | |||
|
648 | end | |||
537 | else |
|
649 | else | |
538 | puts "Mercurial test repository NOT FOUND. Skipping unit tests !!!" |
|
650 | puts "Mercurial test repository NOT FOUND. Skipping unit tests !!!" | |
539 | def test_fake; assert true end |
|
651 | def test_fake; assert true end |
General Comments 0
You need to be logged in to leave comments.
Login now