repository_git_test.rb 22.9 KB
Newer Older
1
# frozen_string_literal: true
2

3
# Redmine - project management software
jplang's avatar
jplang committed
4
# Copyright (C) 2006-2017  Jean-Philippe Lang
5 6 7 8 9
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
# as published by the Free Software Foundation; either version 2
# of the License, or (at your option) any later version.
10
#
11 12 13 14
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
15
#
16 17 18 19
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.

20
require File.expand_path('../../test_helper', __FILE__)
21

22
class RepositoryGitTest < ActiveSupport::TestCase
23 24
  fixtures :projects, :repositories, :enabled_modules, :users, :roles

25 26
  include Redmine::I18n

27
  REPOSITORY_PATH = Rails.root.join('tmp/test/git_repository').to_s
28
  REPOSITORY_PATH.gsub!(/\//, "\\") if Redmine::Platform.mswin?
29

30
  NUM_REV = 28
31
  NUM_HEAD = 6
32

33 34 35 36 37 38 39 40
  ## Git, Mercurial and CVS path encodings are binary.
  ## Subversion supports URL encoding for path.
  ## Redmine Mercurial adapter and extension use URL encoding.
  ## Git accepts only binary path in command line parameter.
  ## So, there is no way to use binary command line parameter in JRuby.
  JRUBY_SKIP     = (RUBY_PLATFORM == 'java')
  JRUBY_SKIP_STR = "TODO: This test fails in JRuby"

41
  def setup
42
    User.current = nil
43 44 45 46 47 48 49 50 51
    @project = Project.find(3)
    @repository = Repository::Git.create(
                        :project       => @project,
                        :url           => REPOSITORY_PATH,
                        :path_encoding => 'ISO-8859-1'
                        )
    assert @repository
  end

52
  def test_nondefault_repo_with_blank_identifier_destruction
jplang's avatar
jplang committed
53 54
    Repository.delete_all

55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82
    repo1 = Repository::Git.new(
                          :project    => @project,
                          :url        => REPOSITORY_PATH,
                          :identifier => '',
                          :is_default => true
                        )
    assert repo1.save
    repo1.fetch_changesets

    repo2 = Repository::Git.new(
                          :project    => @project,
                          :url        => REPOSITORY_PATH,
                          :identifier => 'repo2',
                          :is_default => true
                    )
    assert repo2.save
    repo2.fetch_changesets

    repo1.reload
    repo2.reload
    assert !repo1.is_default?
    assert  repo2.is_default?

    assert_difference 'Repository.count', -1 do
      repo1.destroy
    end
  end

83 84 85 86
  def test_blank_path_to_repository_error_message
    set_language_if_valid 'en'
    repo = Repository::Git.new(
                          :project      => @project,
87
                          :identifier   => 'test'
88 89
                        )
    assert !repo.save
90
    assert_include "Path to repository cannot be blank",
91 92 93 94 95 96 97 98 99
                   repo.errors.full_messages
  end

  def test_blank_path_to_repository_error_message_fr
    set_language_if_valid 'fr'
    repo = Repository::Git.new(
                          :project      => @project,
                          :url          => "",
                          :identifier   => 'test',
100
                          :path_encoding => ''
101 102
                        )
    assert !repo.save
103
    assert_include 'Chemin du dépôt doit être renseigné(e)', repo.errors.full_messages
104 105
  end

106
  if File.directory?(REPOSITORY_PATH)
107 108 109 110 111 112 113 114 115 116
    ## Ruby uses ANSI api to fork a process on Windows.
    ## Japanese Shift_JIS and Traditional Chinese Big5 have 0x5c(backslash) problem
    ## and these are incompatible with ASCII.
    ## Git for Windows (msysGit) changed internal API from ANSI to Unicode in 1.7.10
    ## http://code.google.com/p/msysgit/issues/detail?id=80
    ## So, Latin-1 path tests fail on Japanese Windows
    WINDOWS_PASS = (Redmine::Platform.mswin? &&
                         Redmine::Scm::Adapters::GitAdapter.client_version_above?([1, 7, 10]))
    WINDOWS_SKIP_STR = "TODO: This test fails in Git for Windows above 1.7.10"

117
    def test_scm_available
118 119 120 121 122 123
      klass = Repository::Git
      assert_equal "Git", klass.scm_name
      assert klass.scm_adapter_class
      assert_not_equal "", klass.scm_command
      assert_equal true, klass.scm_available
    end
124

125 126 127 128 129
    def test_entries
      entries = @repository.entries
      assert_kind_of Redmine::Scm::Adapters::Entries, entries
    end

130
    def test_fetch_changesets_from_scratch
131 132
      assert_nil @repository.extra_info

133
      assert_equal 0, @repository.changesets.count
134
      @repository.fetch_changesets
135
      @project.reload
136

137
      assert_equal NUM_REV, @repository.changesets.count
138
      assert_equal 39, @repository.filechanges.count
139

140 141
      commit = @repository.changesets.find_by_revision("7234cb2750b63f47bff735edc50a1c0a433c2518")
      assert_equal "7234cb2750b63f47bff735edc50a1c0a433c2518", commit.scmid
142 143
      assert_equal "Initial import.\nThe repository contains 3 files.", commit.comments
      assert_equal "jsmith <jsmith@foo.bar>", commit.committer
144
      assert_equal User.find_by_login('jsmith'), commit.user
145
      # TODO: add a commit with commit time <> author time to the test repository
146
      assert_equal Time.gm(2007, 12, 14, 9, 22, 52), commit.committed_on
147
      assert_equal "2007-12-14".to_date, commit.commit_date
148 149
      assert_equal 3, commit.filechanges.count
      change = commit.filechanges.sort_by(&:path).first
150
      assert_equal "README", change.path
151
      assert_nil change.from_path
152
      assert_equal "A", change.action
153

154
      assert_equal NUM_HEAD, @repository.extra_info["heads"].size
155
    end
156

157
    def test_fetch_changesets_incremental
158
      assert_equal 0, @repository.changesets.count
159
      @repository.fetch_changesets
160 161
      @project.reload
      assert_equal NUM_REV, @repository.changesets.count
162 163 164 165 166
      extra_info_heads = @repository.extra_info["heads"].dup
      assert_equal NUM_HEAD, extra_info_heads.size
      extra_info_heads.delete_if { |x| x == "83ca5fd546063a3c7dc2e568ba3355661a9e2b2c" }
      assert_equal 4, extra_info_heads.size

167 168 169 170 171 172 173 174 175 176 177
      del_revs = [
          "83ca5fd546063a3c7dc2e568ba3355661a9e2b2c",
          "ed5bb786bbda2dee66a2d50faf51429dbc043a7b",
          "4f26664364207fa8b1af9f8722647ab2d4ac5d43",
          "deff712f05a90d96edbd70facc47d944be5897e3",
          "32ae898b720c2f7eec2723d5bdd558b4cb2d3ddf",
          "7e61ac704deecde634b51e59daa8110435dcb3da",
         ]
      @repository.changesets.each do |rev|
        rev.destroy if del_revs.detect {|r| r == rev.scmid.to_s }
      end
178
      @project.reload
179
      cs1 = @repository.changesets
180 181 182 183
      assert_equal NUM_REV - 6, cs1.count
      extra_info_heads << "4a07fe31bffcf2888791f3e6cbc9c4545cefe3e8"
      h = {}
      h["heads"] = extra_info_heads
184 185
      @repository.merge_extra_info(h)
      @repository.save
186
      @project.reload
187
      assert @repository.extra_info["heads"].index("4a07fe31bffcf2888791f3e6cbc9c4545cefe3e8")
188
      @repository.fetch_changesets
189 190
      @project.reload
      assert_equal NUM_REV, @repository.changesets.count
191 192
      assert_equal NUM_HEAD, @repository.extra_info["heads"].size
      assert @repository.extra_info["heads"].index("83ca5fd546063a3c7dc2e568ba3355661a9e2b2c")
193
    end
194

195
    def test_fetch_changesets_history_editing
196
      assert_equal 0, @repository.changesets.count
197
      @repository.fetch_changesets
198 199
      @project.reload
      assert_equal NUM_REV, @repository.changesets.count
200 201 202 203 204
      extra_info_heads = @repository.extra_info["heads"].dup
      assert_equal NUM_HEAD, extra_info_heads.size
      extra_info_heads.delete_if { |x| x == "83ca5fd546063a3c7dc2e568ba3355661a9e2b2c" }
      assert_equal 4, extra_info_heads.size

205 206 207 208 209 210 211 212 213 214 215
      del_revs = [
          "83ca5fd546063a3c7dc2e568ba3355661a9e2b2c",
          "ed5bb786bbda2dee66a2d50faf51429dbc043a7b",
          "4f26664364207fa8b1af9f8722647ab2d4ac5d43",
          "deff712f05a90d96edbd70facc47d944be5897e3",
          "32ae898b720c2f7eec2723d5bdd558b4cb2d3ddf",
          "7e61ac704deecde634b51e59daa8110435dcb3da",
         ]
      @repository.changesets.each do |rev|
        rev.destroy if del_revs.detect {|r| r == rev.scmid.to_s }
      end
216
      @project.reload
217 218 219 220 221 222 223 224 225 226 227
      assert_equal NUM_REV - 6, @repository.changesets.count

      c = Changeset.new(:repository   => @repository,
                        :committed_on => Time.now,
                        :revision     => "abcd1234efgh",
                        :scmid        => "abcd1234efgh",
                        :comments     => 'test')
      assert c.save
      @project.reload
      assert_equal NUM_REV - 5, @repository.changesets.count

228
      extra_info_heads << "1234abcd5678"
229 230
      h = {}
      h["heads"] = extra_info_heads
231 232
      @repository.merge_extra_info(h)
      @repository.save
233
      @project.reload
234
      h1 = @repository.extra_info["heads"].dup
235
      assert h1.index("1234abcd5678")
236
      assert_equal 5, h1.size
237 238

      @repository.fetch_changesets
239
      @project.reload
240
      assert_equal NUM_REV - 5, @repository.changesets.count
241 242
      h2 = @repository.extra_info["heads"].dup
      assert_equal h1, h2
243 244
    end

245
    def test_clear_changesets_should_keep_report_last_commit
246
      assert_nil @repository.extra_info
247
      @repository.report_last_commit = "1"
248 249
      @repository.save
      @repository.send(:clear_changesets)
250 251

      assert_equal true, @repository.report_last_commit
252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269
    end

    def test_refetch_after_clear_changesets
      assert_nil @repository.extra_info
      assert_equal 0, @repository.changesets.count
      @repository.fetch_changesets
      @project.reload
      assert_equal NUM_REV, @repository.changesets.count

      @repository.send(:clear_changesets)
      @project.reload
      assert_equal 0, @repository.changesets.count

      @repository.fetch_changesets
      @project.reload
      assert_equal NUM_REV, @repository.changesets.count
    end

270 271 272 273 274 275 276 277 278 279 280 281 282
    def test_parents
      assert_equal 0, @repository.changesets.count
      @repository.fetch_changesets
      @project.reload
      assert_equal NUM_REV, @repository.changesets.count
      r1 = @repository.find_changeset_by_name("7234cb2750b63")
      assert_equal [], r1.parents
      r2 = @repository.find_changeset_by_name("899a15dba03a3")
      assert_equal 1, r2.parents.length
      assert_equal "7234cb2750b63f47bff735edc50a1c0a433c2518",
                   r2.parents[0].identifier
      r3 = @repository.find_changeset_by_name("32ae898b720c2")
      assert_equal 2, r3.parents.length
283 284 285
      r4 = [r3.parents[0].identifier, r3.parents[1].identifier].sort
      assert_equal "4a07fe31bffcf2888791f3e6cbc9c4545cefe3e8", r4[0]
      assert_equal "7e61ac704deecde634b51e59daa8110435dcb3da", r4[1]
286 287
    end

288 289
    def test_db_consistent_ordering_init
      assert_nil @repository.extra_info
290
      assert_equal 0, @repository.changesets.count
291
      @repository.fetch_changesets
292
      @project.reload
293 294 295
      assert_equal 1, @repository.extra_info["db_consistent"]["ordering"]
    end

296 297
    def test_db_consistent_ordering_before_1_2
      assert_nil @repository.extra_info
298
      assert_equal 0, @repository.changesets.count
299
      @repository.fetch_changesets
300 301
      @project.reload
      assert_equal NUM_REV, @repository.changesets.count
302
      assert_not_nil @repository.extra_info
303 304 305 306 307
      h = {}
      h["heads"] = []
      h["branches"] = {}
      h["db_consistent"] = {}
      @repository.merge_extra_info(h)
308
      @repository.save
309
      assert_equal NUM_REV, @repository.changesets.count
310
      @repository.fetch_changesets
311
      @project.reload
312 313
      assert_equal 0, @repository.extra_info["db_consistent"]["ordering"]

314 315
      extra_info_heads = @repository.extra_info["heads"].dup
      extra_info_heads.delete_if { |x| x == "83ca5fd546063a3c7dc2e568ba3355661a9e2b2c" }
316 317 318 319 320 321 322 323 324 325 326
      del_revs = [
          "83ca5fd546063a3c7dc2e568ba3355661a9e2b2c",
          "ed5bb786bbda2dee66a2d50faf51429dbc043a7b",
          "4f26664364207fa8b1af9f8722647ab2d4ac5d43",
          "deff712f05a90d96edbd70facc47d944be5897e3",
          "32ae898b720c2f7eec2723d5bdd558b4cb2d3ddf",
          "7e61ac704deecde634b51e59daa8110435dcb3da",
         ]
      @repository.changesets.each do |rev|
        rev.destroy if del_revs.detect {|r| r == rev.scmid.to_s }
      end
327
      @project.reload
328
      cs1 = @repository.changesets
329
      assert_equal NUM_REV - 6, cs1.count
330
      assert_equal 0, @repository.extra_info["db_consistent"]["ordering"]
331 332 333 334

      extra_info_heads << "4a07fe31bffcf2888791f3e6cbc9c4545cefe3e8"
      h = {}
      h["heads"] = extra_info_heads
335 336
      @repository.merge_extra_info(h)
      @repository.save
337
      @project.reload
338
      assert @repository.extra_info["heads"].index("4a07fe31bffcf2888791f3e6cbc9c4545cefe3e8")
339
      @repository.fetch_changesets
340
      @project.reload
341
      assert_equal NUM_REV, @repository.changesets.count
342 343
      assert_equal NUM_HEAD, @repository.extra_info["heads"].size

344 345 346
      assert_equal 0, @repository.extra_info["db_consistent"]["ordering"]
    end

347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362
    def test_heads_from_branches_hash
      assert_nil @repository.extra_info
      assert_equal 0, @repository.changesets.count
      assert_equal [], @repository.heads_from_branches_hash
      h = {}
      h["branches"] = {}
      h["branches"]["test1"] = {}
      h["branches"]["test1"]["last_scmid"] = "1234abcd"
      h["branches"]["test2"] = {}
      h["branches"]["test2"]["last_scmid"] = "abcd1234"
      @repository.merge_extra_info(h)
      @repository.save
      @project.reload
      assert_equal ["1234abcd", "abcd1234"], @repository.heads_from_branches_hash.sort
    end

363
    def test_latest_changesets
364
      assert_equal 0, @repository.changesets.count
365
      @repository.fetch_changesets
366 367
      @project.reload
      assert_equal NUM_REV, @repository.changesets.count
368
      # with limit
369
      changesets = @repository.latest_changesets('', 'master', 2)
370 371 372
      assert_equal 2, changesets.size

      # with path
373
      changesets = @repository.latest_changesets('images', 'master')
374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389
      assert_equal [
              'deff712f05a90d96edbd70facc47d944be5897e3',
              '899a15dba03a3b350b89c3f537e4bbe02a03cdc9',
              '7234cb2750b63f47bff735edc50a1c0a433c2518',
          ], changesets.collect(&:revision)

      changesets = @repository.latest_changesets('README', nil)
      assert_equal [
              '32ae898b720c2f7eec2723d5bdd558b4cb2d3ddf',
              '4a07fe31bffcf2888791f3e6cbc9c4545cefe3e8',
              '713f4944648826f558cf548222f813dabe7cbb04',
              '61b685fbe55ab05b5ac68402d5720c1a6ac973d1',
              '899a15dba03a3b350b89c3f537e4bbe02a03cdc9',
              '7234cb2750b63f47bff735edc50a1c0a433c2518',
          ], changesets.collect(&:revision)

390
      # with path, revision and limit
391 392 393 394 395 396
      changesets = @repository.latest_changesets('images', '899a15dba')
      assert_equal [
              '899a15dba03a3b350b89c3f537e4bbe02a03cdc9',
              '7234cb2750b63f47bff735edc50a1c0a433c2518',
          ], changesets.collect(&:revision)

397 398 399 400 401
      changesets = @repository.latest_changesets('images', '899a15dba', 1)
      assert_equal [
              '899a15dba03a3b350b89c3f537e4bbe02a03cdc9',
          ], changesets.collect(&:revision)

402 403 404 405 406
      changesets = @repository.latest_changesets('README', '899a15dba')
      assert_equal [
              '899a15dba03a3b350b89c3f537e4bbe02a03cdc9',
              '7234cb2750b63f47bff735edc50a1c0a433c2518',
          ], changesets.collect(&:revision)
407 408 409 410 411 412

      changesets = @repository.latest_changesets('README', '899a15dba', 1)
      assert_equal [
              '899a15dba03a3b350b89c3f537e4bbe02a03cdc9',
          ], changesets.collect(&:revision)

413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434
      # with path, tag and limit
      changesets = @repository.latest_changesets('images', 'tag01.annotated')
      assert_equal [
              '899a15dba03a3b350b89c3f537e4bbe02a03cdc9',
              '7234cb2750b63f47bff735edc50a1c0a433c2518',
          ], changesets.collect(&:revision)

      changesets = @repository.latest_changesets('images', 'tag01.annotated', 1)
      assert_equal [
              '899a15dba03a3b350b89c3f537e4bbe02a03cdc9',
          ], changesets.collect(&:revision)

      changesets = @repository.latest_changesets('README', 'tag01.annotated')
      assert_equal [
              '899a15dba03a3b350b89c3f537e4bbe02a03cdc9',
              '7234cb2750b63f47bff735edc50a1c0a433c2518',
          ], changesets.collect(&:revision)

      changesets = @repository.latest_changesets('README', 'tag01.annotated', 1)
      assert_equal [
              '899a15dba03a3b350b89c3f537e4bbe02a03cdc9',
          ], changesets.collect(&:revision)
435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460

      # with path, branch and limit
      changesets = @repository.latest_changesets('images', 'test_branch')
      assert_equal [
              '899a15dba03a3b350b89c3f537e4bbe02a03cdc9',
              '7234cb2750b63f47bff735edc50a1c0a433c2518',
          ], changesets.collect(&:revision)

      changesets = @repository.latest_changesets('images', 'test_branch', 1)
      assert_equal [
              '899a15dba03a3b350b89c3f537e4bbe02a03cdc9',
          ], changesets.collect(&:revision)

      changesets = @repository.latest_changesets('README', 'test_branch')
      assert_equal [
              '713f4944648826f558cf548222f813dabe7cbb04',
              '61b685fbe55ab05b5ac68402d5720c1a6ac973d1',
              '899a15dba03a3b350b89c3f537e4bbe02a03cdc9',
              '7234cb2750b63f47bff735edc50a1c0a433c2518',
          ], changesets.collect(&:revision)

      changesets = @repository.latest_changesets('README', 'test_branch', 2)
      assert_equal [
              '713f4944648826f558cf548222f813dabe7cbb04',
              '61b685fbe55ab05b5ac68402d5720c1a6ac973d1',
          ], changesets.collect(&:revision)
461

462 463 464
      if WINDOWS_PASS
        puts WINDOWS_SKIP_STR
      elsif JRUBY_SKIP
465 466 467 468
        puts JRUBY_SKIP_STR
      else
        # latin-1 encoding path
        changesets = @repository.latest_changesets(
469
                      'latin-1-dir/test-Ü-2.txt', '64f1f3e89')
470
        assert_equal [
471 472 473 474
              '64f1f3e89ad1cb57976ff0ad99a107012ba3481d',
              '4fc55c43bf3d3dc2efb66145365ddc17639ce81e',
          ], changesets.collect(&:revision)

475
        changesets = @repository.latest_changesets(
476
                    'latin-1-dir/test-Ü-2.txt', '64f1f3e89', 1)
477
        assert_equal [
478 479
              '64f1f3e89ad1cb57976ff0ad99a107012ba3481d',
          ], changesets.collect(&:revision)
480
      end
481 482
    end

483
    def test_latest_changesets_latin_1_dir
484
      if WINDOWS_PASS
485
        puts WINDOWS_SKIP_STR
486 487
      elsif JRUBY_SKIP
        puts JRUBY_SKIP_STR
488
      else
489
        assert_equal 0, @repository.changesets.count
490
        @repository.fetch_changesets
491 492
        @project.reload
        assert_equal NUM_REV, @repository.changesets.count
493
        changesets = @repository.latest_changesets(
494
                    'latin-1-dir/test-Ü-subdir', '1ca7f5ed')
495 496 497 498 499 500
        assert_equal [
              '1ca7f5ed374f3cb31a93ae5215c2e25cc6ec5127',
          ], changesets.collect(&:revision)
      end
    end

501
    def test_find_changeset_by_name
502
      assert_equal 0, @repository.changesets.count
503
      @repository.fetch_changesets
504 505
      @project.reload
      assert_equal NUM_REV, @repository.changesets.count
506 507 508 509 510 511 512
      ['7234cb2750b63f47bff735edc50a1c0a433c2518', '7234cb2750b'].each do |r|
        assert_equal '7234cb2750b63f47bff735edc50a1c0a433c2518',
                     @repository.find_changeset_by_name(r).revision
      end
    end

    def test_find_changeset_by_empty_name
513
      assert_equal 0, @repository.changesets.count
514
      @repository.fetch_changesets
515 516
      @project.reload
      assert_equal NUM_REV, @repository.changesets.count
517 518 519 520 521
      ['', ' ', nil].each do |r|
        assert_nil @repository.find_changeset_by_name(r)
      end
    end

522
    def test_identifier
523
      assert_equal 0, @repository.changesets.count
524
      @repository.fetch_changesets
525 526
      @project.reload
      assert_equal NUM_REV, @repository.changesets.count
527 528
      c = @repository.changesets.find_by_revision(
                          '7234cb2750b63f47bff735edc50a1c0a433c2518')
529 530 531 532
      assert_equal c.scmid, c.identifier
    end

    def test_format_identifier
533
      assert_equal 0, @repository.changesets.count
534
      @repository.fetch_changesets
535 536
      @project.reload
      assert_equal NUM_REV, @repository.changesets.count
537 538
      c = @repository.changesets.find_by_revision(
                          '7234cb2750b63f47bff735edc50a1c0a433c2518')
539
      assert_equal '7234cb27', c.format_identifier
540 541 542
    end

    def test_activities
543 544
      c = Changeset.new(:repository => @repository,
                        :committed_on => Time.now,
545 546 547 548
                        :revision => 'abc7234cb2750b63f47bff735edc50a1c0a433c2',
                        :scmid    => 'abc7234cb2750b63f47bff735edc50a1c0a433c2',
                        :comments => 'test')
      assert c.event_title.include?('abc7234c:')
549
      assert_equal 'abc7234cb2750b63f47bff735edc50a1c0a433c2', c.event_url[:rev]
550
    end
551 552

    def test_log_utf8
553
      assert_equal 0, @repository.changesets.count
554
      @repository.fetch_changesets
555 556
      @project.reload
      assert_equal NUM_REV, @repository.changesets.count
557 558
      c = @repository.changesets.find_by_revision(
                        'ed5bb786bbda2dee66a2d50faf51429dbc043a7b')
559
      assert_equal 'Felix Schäfer <felix@fachschaften.org>', c.committer
560
    end
561 562

    def test_previous
563
      assert_equal 0, @repository.changesets.count
564
      @repository.fetch_changesets
565 566
      @project.reload
      assert_equal NUM_REV, @repository.changesets.count
567 568 569 570 571 572 573 574 575
      %w|1ca7f5ed374f3cb31a93ae5215c2e25cc6ec5127 1ca7f5ed|.each do |r1|
        changeset = @repository.find_changeset_by_name(r1)
        %w|64f1f3e89ad1cb57976ff0ad99a107012ba3481d 64f1f3e89ad1|.each do |r2|
          assert_equal @repository.find_changeset_by_name(r2), changeset.previous
        end
      end
    end

    def test_previous_nil
576
      assert_equal 0, @repository.changesets.count
577
      @repository.fetch_changesets
578 579
      @project.reload
      assert_equal NUM_REV, @repository.changesets.count
580
      %w|7234cb2750b63f47bff735edc50a1c0a433c2518 7234cb275|.each do |r1|
581 582 583 584 585 586
        changeset = @repository.find_changeset_by_name(r1)
        assert_nil changeset.previous
      end
    end

    def test_next
587
      assert_equal 0, @repository.changesets.count
588
      @repository.fetch_changesets
589 590
      @project.reload
      assert_equal NUM_REV, @repository.changesets.count
591 592 593 594 595 596 597 598 599
      %w|64f1f3e89ad1cb57976ff0ad99a107012ba3481d 64f1f3e89ad1|.each do |r2|
        changeset = @repository.find_changeset_by_name(r2)
        %w|1ca7f5ed374f3cb31a93ae5215c2e25cc6ec5127 1ca7f5ed|.each do |r1|
        assert_equal @repository.find_changeset_by_name(r1), changeset.next
        end
      end
    end

    def test_next_nil
600
      assert_equal 0, @repository.changesets.count
601
      @repository.fetch_changesets
602 603
      @project.reload
      assert_equal NUM_REV, @repository.changesets.count
604
      %w|2a682156a3b6e77a8bf9cd4590e8db757f3c6c78 2a682156a3b6e77a|.each do |r1|
605 606 607 608
        changeset = @repository.find_changeset_by_name(r1)
        assert_nil changeset.next
      end
    end
609 610 611 612 613
  else
    puts "Git test repository NOT FOUND. Skipping unit tests !!!"
    def test_fake; assert true end
  end
end