]> source.dussan.org Git - redmine.git/commitdiff
Show renames in diff preview (#28295).
authorGo MAEDA <maeda@farend.jp>
Fri, 27 Apr 2018 09:14:36 +0000 (09:14 +0000)
committerGo MAEDA <maeda@farend.jp>
Fri, 27 Apr 2018 09:14:36 +0000 (09:14 +0000)
Patch by Gregor Schmidt.

git-svn-id: http://svn.redmine.org/redmine/trunk@17313 e93f8b46-1217-0410-a6f0-8f06a7374b81

app/views/common/_diff.html.erb
lib/redmine/unified_diff.rb
public/stylesheets/scm.css
test/unit/lib/redmine/unified_diff_test.rb

index 0d30bedd215515579596cdc885ff010d549086a4..35dfdea283b5a2c42e36f381e83efd4fd215223f 100644 (file)
@@ -10,6 +10,9 @@
 <thead>
 <tr>
   <th colspan="4" class="filename">
+    <% if table_file.previous_file_name %>
+      <span class="previous-filename"><%= table_file.previous_file_name %> →</span>
+    <% end %>
     <%= table_file.file_name %>
   </th>
 </tr>
@@ -40,6 +43,9 @@
 <thead>
   <tr>
     <th colspan="3" class="filename">
+      <% if table_file.previous_file_name %>
+        <span class="previous-filename"><%= table_file.previous_file_name %> →</span>
+      <% end %>
       <%= table_file.file_name %>
     </th>
   </tr>
index 7e2e20286585ec398f5fb231d1aaf48814cdbb27..ae68d5dfc1b8b7218f93d4770ce3d5ddfe4adf3d 100644 (file)
@@ -49,7 +49,7 @@ module Redmine
 
   # Class that represents a file diff
   class DiffTable < Array
-    attr_reader :file_name
+    attr_reader :file_name, :previous_file_name
 
     # Initialize with a Diff file and the type of Diff View
     # The type view must be inline or sbs (side_by_side)
@@ -60,6 +60,7 @@ module Redmine
       @type = type
       @style = style
       @file_name = nil
+      @previous_file_name = nil
       @git_diff = false
     end
 
@@ -120,8 +121,12 @@ module Redmine
           # keep the original file name
           @file_name = file_name.sub(%r{^a/}, '')
         else
+          # remove leading a/
+          @previous_file_name = file_name.sub(%r{^a/}, '') unless file_name == "/dev/null"
           # remove leading b/
           @file_name = arg.sub(%r{^b/}, '')
+
+          @previous_file_name = nil if @previous_file_name == @file_name
         end
       elsif @style == "Subversion"
         # removing trailing "(revision nn)"
index 946b85ed5df8825b99c6d3b02870cde2a276f787..b582d04e5264de1483260a2c44a331fe391898ec 100644 (file)
@@ -73,6 +73,10 @@ table.filecontent tr:target td.line-code { background-color:#DDEEFF; }
 
 img.filecontent { max-width: 100%; }
 
+.previous-filename {
+  font-weight: normal;
+}
+
 /* 12 different colors for the annonate view */
 table.annotate tr.bloc-0 td.author {border-right-color: #FFFFBF;}
 table.annotate tr.bloc-1 td.author {border-right-color: #EABFFF;}
index eb373abe617c2db7c18557d7eab4b7045ce3103d..0a09a0fb4f8cbd2c4c63c1026f4a9c4689e947f0 100644 (file)
@@ -189,6 +189,56 @@ DIFF
     assert_equal "test1.txt", diff[0].file_name
   end
 
+  def test_previous_file_name_with_git
+    diff = Redmine::UnifiedDiff.new(<<-DIFF)
+From 585da9683fb5ed7bf7cb438492e3347cdf3d83df Mon Sep 17 00:00:00 2001
+From: Gregor Schmidt <schmidt@nach-vorne.eu>
+Date: Mon, 5 Mar 2018 14:12:13 +0100
+Subject: [PATCH] changes including a rename, rename+modify and addition
+
+---
+ one.markdown => one.md | 0
+ three.md               | 2 ++
+ two.markdown => two.md | 1 +
+ 3 files changed, 3 insertions(+)
+ rename one.markdown => one.md (100%)
+ create mode 100644 three.md
+ rename two.markdown => two.md (50%)
+
+diff --git a/one.markdown b/one.md
+similarity index 100%
+rename from one.markdown
+rename to one.md
+diff --git a/three.md b/three.md
+new file mode 100644
+index 0000000..288012f
+--- /dev/null
++++ b/three.md
+@@ -0,0 +1,2 @@
++three
++=====
+diff --git a/two.markdown b/two.md
+similarity index 50%
+rename from two.markdown
+rename to two.md
+index f719efd..6a268ed 100644
+--- a/two.markdown
++++ b/two.md
+@@ -1 +1,2 @@
+ two
++===
+--
+2.14.1
+DIFF
+
+    assert_equal 2, diff.size
+    assert_equal "three.md", diff[0].file_name
+    assert_nil               diff[0].previous_file_name
+
+    assert_equal "two.md",       diff[1].file_name
+    assert_equal "two.markdown", diff[1].previous_file_name
+  end
+
   def test_include_a_b_slash
     diff = Redmine::UnifiedDiff.new(<<-DIFF
 --- test1.txt