]> source.dussan.org Git - redmine.git/commitdiff
use git diff format for all diff (#11868)
authorToshi MARUYAMA <marutosijp2@yahoo.co.jp>
Wed, 19 Sep 2012 02:29:11 +0000 (02:29 +0000)
committerToshi MARUYAMA <marutosijp2@yahoo.co.jp>
Wed, 19 Sep 2012 02:29:11 +0000 (02:29 +0000)
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
test/functional/repositories_mercurial_controller_test.rb
test/unit/lib/redmine/unified_diff_test.rb

index 7649ed6532e9c678164196653ddd28097faef63e..07ea28f5202cbdcfa2e1040f5173f5ae6fe141cd 100644 (file)
@@ -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
index bfcf2d66959527cf126cbadb6a82cc47f5c6b744..d4cefbd229def9e3ee3594a7ad33aa485efb8b71 100644 (file)
@@ -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]
index 52c5ccf5fb509fd9afd0340c64d0b8d7c225f229..61ed3df83a2c4da48c1b099b87dff765c3206ba1 100644 (file)
@@ -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