Project

General

Profile

Patch #28295 » 0001-Show-renames-in-diff-preview.patch

Gregor Schmidt, 2018-03-05 14:58

View differences:

app/views/common/_diff.html.erb
10 10
<thead>
11 11
<tr>
12 12
  <th colspan="4" class="filename">
13
    <% if table_file.previous_file_name %>
14
      <span class="previous-filename"><%= table_file.previous_file_name %> →</span>
15
    <% end %>
13 16
    <%= table_file.file_name %>
14 17
  </th>
15 18
</tr>
......
40 43
<thead>
41 44
  <tr>
42 45
    <th colspan="3" class="filename">
46
      <% if table_file.previous_file_name %>
47
        <span class="previous-filename"><%= table_file.previous_file_name %> →</span>
48
      <% end %>
43 49
      <%= table_file.file_name %>
44 50
    </th>
45 51
  </tr>
lib/redmine/unified_diff.rb
49 49

  
50 50
  # Class that represents a file diff
51 51
  class DiffTable < Array
52
    attr_reader :file_name
52
    attr_reader :file_name, :previous_file_name
53 53

  
54 54
    # Initialize with a Diff file and the type of Diff View
55 55
    # The type view must be inline or sbs (side_by_side)
......
60 60
      @type = type
61 61
      @style = style
62 62
      @file_name = nil
63
      @previous_file_name = nil
63 64
      @git_diff = false
64 65
    end
65 66

  
......
120 121
          # keep the original file name
121 122
          @file_name = file_name.sub(%r{^a/}, '')
122 123
        else
124
          # remove leading a/
125
          @previous_file_name = file_name.sub(%r{^a/}, '') unless file_name == "/dev/null"
123 126
          # remove leading b/
124 127
          @file_name = arg.sub(%r{^b/}, '')
125 128
        end
public/stylesheets/scm.css
73 73

  
74 74
img.filecontent { max-width: 100%; }
75 75

  
76
.previous-filename {
77
  font-weight: normal;
78
}
79

  
76 80
/* 12 different colors for the annonate view */
77 81
table.annotate tr.bloc-0 td.author {border-right-color: #FFFFBF;}
78 82
table.annotate tr.bloc-1 td.author {border-right-color: #EABFFF;}
test/unit/lib/redmine/unified_diff_test.rb
189 189
    assert_equal "test1.txt", diff[0].file_name
190 190
  end
191 191

  
192
  def test_previous_file_name_with_git
193
    diff = Redmine::UnifiedDiff.new(<<-DIFF)
194
From 585da9683fb5ed7bf7cb438492e3347cdf3d83df Mon Sep 17 00:00:00 2001
195
From: Gregor Schmidt <schmidt@nach-vorne.eu>
196
Date: Mon, 5 Mar 2018 14:12:13 +0100
197
Subject: [PATCH] changes including a rename, rename+modify and addition
198

  
199
---
200
 one.markdown => one.md | 0
201
 three.md               | 2 ++
202
 two.markdown => two.md | 1 +
203
 3 files changed, 3 insertions(+)
204
 rename one.markdown => one.md (100%)
205
 create mode 100644 three.md
206
 rename two.markdown => two.md (50%)
207

  
208
diff --git a/one.markdown b/one.md
209
similarity index 100%
210
rename from one.markdown
211
rename to one.md
212
diff --git a/three.md b/three.md
213
new file mode 100644
214
index 0000000..288012f
215
--- /dev/null
216
+++ b/three.md
217
@@ -0,0 +1,2 @@
218
+three
219
+=====
220
diff --git a/two.markdown b/two.md
221
similarity index 50%
222
rename from two.markdown
223
rename to two.md
224
index f719efd..6a268ed 100644
225
--- a/two.markdown
226
+++ b/two.md
227
@@ -1 +1,2 @@
228
 two
229
+===
230
--
231
2.14.1
232
DIFF
233

  
234
    assert_equal 2, diff.size
235
    assert_equal "three.md", diff[0].file_name
236
    assert_nil               diff[0].previous_file_name
237

  
238
    assert_equal "two.md",       diff[1].file_name
239
    assert_equal "two.markdown", diff[1].previous_file_name
240
  end
241

  
192 242
  def test_include_a_b_slash
193 243
    diff = Redmine::UnifiedDiff.new(<<-DIFF
194 244
--- test1.txt
(1-1/3)