@@ -227,16 +227,25 module Redmine | |||
|
227 | 227 | |
|
228 | 228 | def annotate(path, identifier=nil) |
|
229 | 229 | identifier = 'HEAD' if identifier.blank? |
|
230 |
cmd = "#{GIT_BIN} --git-dir #{target('')} blame - |
|
|
230 | cmd = "#{GIT_BIN} --git-dir #{target('')} blame -p #{shell_quote identifier} -- #{shell_quote path}" | |
|
231 | 231 | blame = Annotate.new |
|
232 | 232 | content = nil |
|
233 | 233 | shellout(cmd) { |io| io.binmode; content = io.read } |
|
234 | 234 | return nil if $? && $?.exitstatus != 0 |
|
235 | 235 | # git annotates binary files |
|
236 | 236 | return nil if content.is_binary_data? |
|
237 | identifier = '' | |
|
238 | author = '' | |
|
237 | 239 | content.split("\n").each do |line| |
|
238 |
|
|
|
239 | blame.add_line($3.rstrip, Revision.new(:identifier => $1, :author => $2.strip)) | |
|
240 | if line =~ /^([0-9a-f]{39,40})\s.*/ | |
|
241 | identifier = $1 | |
|
242 | elsif line =~ /^author (.+)/ | |
|
243 | author = $1.strip | |
|
244 | elsif line =~ /^\t(.*)/ | |
|
245 | blame.add_line($1, Revision.new(:identifier => identifier, :author => author)) | |
|
246 | identifier = '' | |
|
247 | author = '' | |
|
248 | end | |
|
240 | 249 | end |
|
241 | 250 | blame |
|
242 | 251 | end |
@@ -15,6 +15,20 class GitAdapterTest < ActiveSupport::TestCase | |||
|
15 | 15 | def test_getting_all_revisions |
|
16 | 16 | assert_equal 12, @adapter.revisions('',nil,nil,:all => true).length |
|
17 | 17 | end |
|
18 | ||
|
19 | def test_annotate | |
|
20 | annotate = @adapter.annotate('sources/watchers_controller.rb') | |
|
21 | assert_kind_of Redmine::Scm::Adapters::Annotate, annotate | |
|
22 | assert_equal 41, annotate.lines.size | |
|
23 | end | |
|
24 | ||
|
25 | def test_annotate_moved_file | |
|
26 | annotate = @adapter.annotate('renamed_test.txt') | |
|
27 | assert_kind_of Redmine::Scm::Adapters::Annotate, annotate | |
|
28 | assert_equal 2, annotate.lines.size | |
|
29 | assert_equal "Let's pretend I'm adding a new feature!", annotate.lines.second | |
|
30 | assert_equal "7e61ac704deecde634b51e59daa8110435dcb3da", annotate.revisions.second.identifier | |
|
31 | end | |
|
18 | 32 | else |
|
19 | 33 | puts "Git test repository NOT FOUND. Skipping unit tests !!!" |
|
20 | 34 | def test_fake; assert true end |
General Comments 0
You need to be logged in to leave comments.
Login now