require 'redmine/scm/adapters/mercurial_adapter'
class Repository::Mercurial < Repository
+ # sort changesets by revision number
+ has_many :changesets, :order => "#{Changeset.table_name}.id DESC", :foreign_key => 'repository_id'
+
attr_protected :root_url
validates_presence_of :url
entries
end
+ # Returns the latest changesets for +path+; sorted by revision number
+ def latest_changesets(path, rev, limit=10)
+ if path.blank?
+ changesets.find(:all, :include => :user, :limit => limit)
+ else
+ changes.find(:all, :include => {:changeset => :user},
+ :conditions => ["path = ?", path.with_leading_slash],
+ :order => "#{Changeset.table_name}.id DESC",
+ :limit => limit).collect(&:changeset)
+ end
+ end
+
def fetch_changesets
scm_info = scm.info
if scm_info
assert_equal @repository.changesets.find_by_revision('0').committed_on, rev0_committed_on
end
end
+
+ def test_changeset_order_by_revision
+ @repository.fetch_changesets
+ @repository.reload
+
+ c0 = @repository.latest_changeset
+ c1 = @repository.changesets.find_by_revision('0')
+ # sorted by revision (id), not by date
+ assert c0.revision.to_i > c1.revision.to_i
+ assert c0.committed_on < c1.committed_on
+ end
else
puts "Mercurial test repository NOT FOUND. Skipping unit tests !!!"
def test_fake; assert true end