From f18edc4e1c045b968cba8d8f905257e63a1c0d5c Mon Sep 17 00:00:00 2001 From: Toshi MARUYAMA Date: Wed, 19 Sep 2012 02:29:11 +0000 Subject: [PATCH] use git diff format for all diff (#11868) Mercurial diff uses git format. git-svn-id: svn+ssh://rubyforge.org/var/svn/redmine/trunk@10428 e93f8b46-1217-0410-a6f0-8f06a7374b81 --- lib/redmine/unified_diff.rb | 17 ++++-- .../repositories_mercurial_controller_test.rb | 14 +++++ test/unit/lib/redmine/unified_diff_test.rb | 54 +++++++++++++++++++ 3 files changed, 80 insertions(+), 5 deletions(-) diff --git a/lib/redmine/unified_diff.rb b/lib/redmine/unified_diff.rb index 7649ed653..07ea28f52 100644 --- a/lib/redmine/unified_diff.rb +++ b/lib/redmine/unified_diff.rb @@ -68,6 +68,7 @@ module Redmine @type = type @style = style @file_name = nil + @git_diff = false end # Function for add a line of this Diff @@ -116,15 +117,21 @@ module Redmine private def file_name=(arg) - case @style - when "Git" + both_git_diff = false + if file_name.nil? + @git_diff = true if arg =~ %r{^(a/|/dev/null)} + else + both_git_diff = (@git_diff && arg =~ %r{^(b/|/dev/null)}) + end + if both_git_diff if file_name && arg == "/dev/null" # keep the original file name + @file_name = file_name.sub(%r{^a/}, '') else - # remove leading a/ b/ - @file_name = arg.sub(%r{^(a|b)/}, '') + # remove leading b/ + @file_name = arg.sub(%r{^b/}, '') end - when "Subversion" + elsif @style == "Subversion" # removing trailing "(revision nn)" @file_name = arg.sub(%r{\t+\(.*\)$}, '') else diff --git a/test/functional/repositories_mercurial_controller_test.rb b/test/functional/repositories_mercurial_controller_test.rb index bfcf2d669..d4cefbd22 100644 --- a/test/functional/repositories_mercurial_controller_test.rb +++ b/test/functional/repositories_mercurial_controller_test.rb @@ -371,6 +371,20 @@ class RepositoriesMercurialControllerTest < ActionController::TestCase end end + def test_diff_should_show_modified_filenames + get :diff, :id => PRJ_ID, :rev => '400bb8672109', :type => 'inline' + assert_response :success + assert_template 'diff' + assert_select 'th.filename', :text => 'sources/watchers_controller.rb' + end + + def test_diff_should_show_deleted_filenames + get :diff, :id => PRJ_ID, :rev => 'b3a615152df8', :type => 'inline' + assert_response :success + assert_template 'diff' + assert_select 'th.filename', :text => 'sources/welcome_controller.rb' + end + def test_annotate get :annotate, :id => PRJ_ID, :path => repository_path_hash(['sources', 'watchers_controller.rb'])[:param] diff --git a/test/unit/lib/redmine/unified_diff_test.rb b/test/unit/lib/redmine/unified_diff_test.rb index 52c5ccf5f..61ed3df83 100644 --- a/test/unit/lib/redmine/unified_diff_test.rb +++ b/test/unit/lib/redmine/unified_diff_test.rb @@ -169,6 +169,60 @@ diff -r 000000000000 -r ea98b14f75f0 README4 DIFF ) assert_equal 4, diff.size + assert_equal "README1", diff[0].file_name + end + + def test_both_git_diff + diff = Redmine::UnifiedDiff.new(<<-DIFF +# HG changeset patch +# User test +# Date 1348014182 -32400 +# Node ID d1c871b8ef113df7f1c56d41e6e3bfbaff976e1f +# Parent 180b6605936cdc7909c5f08b59746ec1a7c99b3e +modify test1.txt + +diff -r 180b6605936c -r d1c871b8ef11 test1.txt +--- a/test1.txt ++++ b/test1.txt +@@ -1,1 +1,1 @@ +-test1 ++modify test1 +DIFF + ) + assert_equal 1, diff.size + assert_equal "test1.txt", diff[0].file_name + end + + def test_include_a_b_slash + diff = Redmine::UnifiedDiff.new(<<-DIFF +--- test1.txt ++++ b/test02.txt +@@ -1 +0,0 @@ +-modify test1 +DIFF + ) + assert_equal 1, diff.size + assert_equal "b/test02.txt", diff[0].file_name + + diff = Redmine::UnifiedDiff.new(<<-DIFF +--- a/test1.txt ++++ a/test02.txt +@@ -1 +0,0 @@ +-modify test1 +DIFF + ) + assert_equal 1, diff.size + assert_equal "a/test02.txt", diff[0].file_name + + diff = Redmine::UnifiedDiff.new(<<-DIFF +--- a/test1.txt ++++ test02.txt +@@ -1 +0,0 @@ +-modify test1 +DIFF + ) + assert_equal 1, diff.size + assert_equal "test02.txt", diff[0].file_name end private -- 2.39.5