diff --git a/lib/redmine/scm/adapters/mercurial_adapter.rb b/lib/redmine/scm/adapters/mercurial_adapter.rb index be755419..7607dd1c 100644 --- a/lib/redmine/scm/adapters/mercurial_adapter.rb +++ b/lib/redmine/scm/adapters/mercurial_adapter.rb @@ -153,15 +153,13 @@ module Redmine def diff(path, identifier_from, identifier_to=nil) path ||= '' + diff_args = '' if identifier_to - identifier_to = identifier_to.to_i + diff_args = "-r #{hgrev(identifier_to)} -r #{hgrev(identifier_from)}" else - identifier_to = identifier_from.to_i - 1 + diff_args = "-c #{hgrev(identifier_from)}" end - if identifier_from - identifier_from = identifier_from.to_i - end - cmd = "#{HG_BIN} -R #{target('')} diff -r #{identifier_to} -r #{identifier_from} --nodates" + cmd = "#{HG_BIN} -R #{target('')} diff --nodates #{diff_args}" cmd << " -I #{target(path)}" unless path.empty? diff = [] shellout(cmd) do |io| @@ -203,6 +201,12 @@ module Redmine return nil if $? && $?.exitstatus != 0 blame end + + # Returns correct revision identifier + def hgrev(identifier) + identifier.blank? ? 'tip' : identifier.to_s + end + private :hgrev end end end diff --git a/test/unit/lib/redmine/scm/adapters/mercurial_adapter_test.rb b/test/unit/lib/redmine/scm/adapters/mercurial_adapter_test.rb index afd7b270..088664bd 100644 --- a/test/unit/lib/redmine/scm/adapters/mercurial_adapter_test.rb +++ b/test/unit/lib/redmine/scm/adapters/mercurial_adapter_test.rb @@ -42,6 +42,24 @@ begin end end + def test_diff + assert_nil @adapter.diff(nil, '100000') + assert_nil @adapter.diff(nil, '100000', '200000') + [2, '400bb8672109', '400', 400].each do |r1| + diff1 = @adapter.diff(nil, r1) + assert_equal 28, diff1.size + assert_equal "+ return true unless klass.respond_to?('watched_by')\r\n", diff1[24] + [4, 'def6d2f1254a'].each do |r2| + diff2 = @adapter.diff(nil,r1,r2) + assert_equal 50, diff2.size + assert_equal "+class WelcomeController < ApplicationController\r\n", diff2[42] + diff3 = @adapter.diff('sources/watchers_controller.rb', r1, r2) + assert_equal 20, diff3.size + assert_equal "+ @watched.remove_watcher(user)\r\n", diff3[12] + end + end + end + def test_cat [2, '400bb8672109', '400', 400].each do |r| buf = @adapter.cat('sources/welcome_controller.rb', r)