@@ -68,6 +68,7 module Redmine | |||
|
68 | 68 | @type = type |
|
69 | 69 | @style = style |
|
70 | 70 | @file_name = nil |
|
71 | @git_diff = false | |
|
71 | 72 | end |
|
72 | 73 | |
|
73 | 74 | # Function for add a line of this Diff |
@@ -116,15 +117,21 module Redmine | |||
|
116 | 117 | private |
|
117 | 118 | |
|
118 | 119 | def file_name=(arg) |
|
119 | case @style | |
|
120 | when "Git" | |
|
120 | both_git_diff = false | |
|
121 | if file_name.nil? | |
|
122 | @git_diff = true if arg =~ %r{^(a/|/dev/null)} | |
|
123 | else | |
|
124 | both_git_diff = (@git_diff && arg =~ %r{^(b/|/dev/null)}) | |
|
125 | end | |
|
126 | if both_git_diff | |
|
121 | 127 | if file_name && arg == "/dev/null" |
|
122 | 128 | # keep the original file name |
|
129 | @file_name = file_name.sub(%r{^a/}, '') | |
|
123 | 130 | else |
|
124 |
# remove leading |
|
|
125 |
@file_name = arg.sub(%r{^ |
|
|
131 | # remove leading b/ | |
|
132 | @file_name = arg.sub(%r{^b/}, '') | |
|
126 | 133 | end |
|
127 |
|
|
|
134 | elsif @style == "Subversion" | |
|
128 | 135 | # removing trailing "(revision nn)" |
|
129 | 136 | @file_name = arg.sub(%r{\t+\(.*\)$}, '') |
|
130 | 137 | else |
@@ -371,6 +371,20 class RepositoriesMercurialControllerTest < ActionController::TestCase | |||
|
371 | 371 | end |
|
372 | 372 | end |
|
373 | 373 | |
|
374 | def test_diff_should_show_modified_filenames | |
|
375 | get :diff, :id => PRJ_ID, :rev => '400bb8672109', :type => 'inline' | |
|
376 | assert_response :success | |
|
377 | assert_template 'diff' | |
|
378 | assert_select 'th.filename', :text => 'sources/watchers_controller.rb' | |
|
379 | end | |
|
380 | ||
|
381 | def test_diff_should_show_deleted_filenames | |
|
382 | get :diff, :id => PRJ_ID, :rev => 'b3a615152df8', :type => 'inline' | |
|
383 | assert_response :success | |
|
384 | assert_template 'diff' | |
|
385 | assert_select 'th.filename', :text => 'sources/welcome_controller.rb' | |
|
386 | end | |
|
387 | ||
|
374 | 388 | def test_annotate |
|
375 | 389 | get :annotate, :id => PRJ_ID, |
|
376 | 390 | :path => repository_path_hash(['sources', 'watchers_controller.rb'])[:param] |
@@ -169,6 +169,60 diff -r 000000000000 -r ea98b14f75f0 README4 | |||
|
169 | 169 | DIFF |
|
170 | 170 | ) |
|
171 | 171 | assert_equal 4, diff.size |
|
172 | assert_equal "README1", diff[0].file_name | |
|
173 | end | |
|
174 | ||
|
175 | def test_both_git_diff | |
|
176 | diff = Redmine::UnifiedDiff.new(<<-DIFF | |
|
177 | # HG changeset patch | |
|
178 | # User test | |
|
179 | # Date 1348014182 -32400 | |
|
180 | # Node ID d1c871b8ef113df7f1c56d41e6e3bfbaff976e1f | |
|
181 | # Parent 180b6605936cdc7909c5f08b59746ec1a7c99b3e | |
|
182 | modify test1.txt | |
|
183 | ||
|
184 | diff -r 180b6605936c -r d1c871b8ef11 test1.txt | |
|
185 | --- a/test1.txt | |
|
186 | +++ b/test1.txt | |
|
187 | @@ -1,1 +1,1 @@ | |
|
188 | -test1 | |
|
189 | +modify test1 | |
|
190 | DIFF | |
|
191 | ) | |
|
192 | assert_equal 1, diff.size | |
|
193 | assert_equal "test1.txt", diff[0].file_name | |
|
194 | end | |
|
195 | ||
|
196 | def test_include_a_b_slash | |
|
197 | diff = Redmine::UnifiedDiff.new(<<-DIFF | |
|
198 | --- test1.txt | |
|
199 | +++ b/test02.txt | |
|
200 | @@ -1 +0,0 @@ | |
|
201 | -modify test1 | |
|
202 | DIFF | |
|
203 | ) | |
|
204 | assert_equal 1, diff.size | |
|
205 | assert_equal "b/test02.txt", diff[0].file_name | |
|
206 | ||
|
207 | diff = Redmine::UnifiedDiff.new(<<-DIFF | |
|
208 | --- a/test1.txt | |
|
209 | +++ a/test02.txt | |
|
210 | @@ -1 +0,0 @@ | |
|
211 | -modify test1 | |
|
212 | DIFF | |
|
213 | ) | |
|
214 | assert_equal 1, diff.size | |
|
215 | assert_equal "a/test02.txt", diff[0].file_name | |
|
216 | ||
|
217 | diff = Redmine::UnifiedDiff.new(<<-DIFF | |
|
218 | --- a/test1.txt | |
|
219 | +++ test02.txt | |
|
220 | @@ -1 +0,0 @@ | |
|
221 | -modify test1 | |
|
222 | DIFF | |
|
223 | ) | |
|
224 | assert_equal 1, diff.size | |
|
225 | assert_equal "test02.txt", diff[0].file_name | |
|
172 | 226 | end |
|
173 | 227 | |
|
174 | 228 | private |
General Comments 0
You need to be logged in to leave comments.
Login now