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
This commit is contained in:
parent
0af04b8ae0
commit
f18edc4e1c
|
@ -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
|
||||
|
|
|
@ -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]
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Reference in New Issue