Fixed: Git blame/annotate fails on moved files (#3832).
git-svn-id: svn+ssh://rubyforge.org/var/svn/redmine/trunk@3513 e93f8b46-1217-0410-a6f0-8f06a7374b81
This commit is contained in:
parent
d6c299f57d
commit
9a85d4d063
|
@ -227,16 +227,25 @@ module Redmine
|
||||||
|
|
||||||
def annotate(path, identifier=nil)
|
def annotate(path, identifier=nil)
|
||||||
identifier = 'HEAD' if identifier.blank?
|
identifier = 'HEAD' if identifier.blank?
|
||||||
cmd = "#{GIT_BIN} --git-dir #{target('')} blame -l #{shell_quote identifier} -- #{shell_quote path}"
|
cmd = "#{GIT_BIN} --git-dir #{target('')} blame -p #{shell_quote identifier} -- #{shell_quote path}"
|
||||||
blame = Annotate.new
|
blame = Annotate.new
|
||||||
content = nil
|
content = nil
|
||||||
shellout(cmd) { |io| io.binmode; content = io.read }
|
shellout(cmd) { |io| io.binmode; content = io.read }
|
||||||
return nil if $? && $?.exitstatus != 0
|
return nil if $? && $?.exitstatus != 0
|
||||||
# git annotates binary files
|
# git annotates binary files
|
||||||
return nil if content.is_binary_data?
|
return nil if content.is_binary_data?
|
||||||
|
identifier = ''
|
||||||
|
author = ''
|
||||||
content.split("\n").each do |line|
|
content.split("\n").each do |line|
|
||||||
next unless line =~ /([0-9a-f]{39,40})\s\((\w*)[^\)]*\)(.*)/
|
if line =~ /^([0-9a-f]{39,40})\s.*/
|
||||||
blame.add_line($3.rstrip, Revision.new(:identifier => $1, :author => $2.strip))
|
identifier = $1
|
||||||
|
elsif line =~ /^author (.+)/
|
||||||
|
author = $1.strip
|
||||||
|
elsif line =~ /^\t(.*)/
|
||||||
|
blame.add_line($1, Revision.new(:identifier => identifier, :author => author))
|
||||||
|
identifier = ''
|
||||||
|
author = ''
|
||||||
|
end
|
||||||
end
|
end
|
||||||
blame
|
blame
|
||||||
end
|
end
|
||||||
|
|
|
@ -15,6 +15,20 @@ class GitAdapterTest < ActiveSupport::TestCase
|
||||||
def test_getting_all_revisions
|
def test_getting_all_revisions
|
||||||
assert_equal 12, @adapter.revisions('',nil,nil,:all => true).length
|
assert_equal 12, @adapter.revisions('',nil,nil,:all => true).length
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def test_annotate
|
||||||
|
annotate = @adapter.annotate('sources/watchers_controller.rb')
|
||||||
|
assert_kind_of Redmine::Scm::Adapters::Annotate, annotate
|
||||||
|
assert_equal 41, annotate.lines.size
|
||||||
|
end
|
||||||
|
|
||||||
|
def test_annotate_moved_file
|
||||||
|
annotate = @adapter.annotate('renamed_test.txt')
|
||||||
|
assert_kind_of Redmine::Scm::Adapters::Annotate, annotate
|
||||||
|
assert_equal 2, annotate.lines.size
|
||||||
|
assert_equal "Let's pretend I'm adding a new feature!", annotate.lines.second
|
||||||
|
assert_equal "7e61ac704deecde634b51e59daa8110435dcb3da", annotate.revisions.second.identifier
|
||||||
|
end
|
||||||
else
|
else
|
||||||
puts "Git test repository NOT FOUND. Skipping unit tests !!!"
|
puts "Git test repository NOT FOUND. Skipping unit tests !!!"
|
||||||
def test_fake; assert true end
|
def test_fake; assert true end
|
||||||
|
|
Loading…
Reference in New Issue