From 3355ffe029fdecbe78a75f7f459bd93eae835a42 Mon Sep 17 00:00:00 2001 From: Jean-Philippe Lang Date: Wed, 3 Mar 2010 21:15:46 +0000 Subject: [PATCH] Fixes git annotate (#3832). git-svn-id: svn+ssh://rubyforge.org/var/svn/redmine/trunk@3531 e93f8b46-1217-0410-a6f0-8f06a7374b81 --- lib/redmine/scm/adapters/git_adapter.rb | 7 ++++--- test/unit/git_adapter_test.rb | 5 +++-- 2 files changed, 7 insertions(+), 5 deletions(-) diff --git a/lib/redmine/scm/adapters/git_adapter.rb b/lib/redmine/scm/adapters/git_adapter.rb index ae619e0326..d15bce1afd 100644 --- a/lib/redmine/scm/adapters/git_adapter.rb +++ b/lib/redmine/scm/adapters/git_adapter.rb @@ -235,14 +235,15 @@ module Redmine # git annotates binary files return nil if content.is_binary_data? identifier = '' - author = '' + # git shows commit author on the first occurrence only + authors_by_commit = {} content.split("\n").each do |line| if line =~ /^([0-9a-f]{39,40})\s.*/ identifier = $1 elsif line =~ /^author (.+)/ - author = $1.strip + authors_by_commit[identifier] = $1.strip elsif line =~ /^\t(.*)/ - blame.add_line($1, Revision.new(:identifier => identifier, :author => author)) + blame.add_line($1, Revision.new(:identifier => identifier, :author => authors_by_commit[identifier])) identifier = '' author = '' end diff --git a/test/unit/git_adapter_test.rb b/test/unit/git_adapter_test.rb index b75606d6b2..8bc000c4c2 100644 --- a/test/unit/git_adapter_test.rb +++ b/test/unit/git_adapter_test.rb @@ -20,14 +20,15 @@ class GitAdapterTest < ActiveSupport::TestCase annotate = @adapter.annotate('sources/watchers_controller.rb') assert_kind_of Redmine::Scm::Adapters::Annotate, annotate assert_equal 41, annotate.lines.size + assert_equal "# This program is free software; you can redistribute it and/or", annotate.lines[4].strip + assert_equal "7234cb2750b63f47bff735edc50a1c0a433c2518", annotate.revisions[4].identifier + assert_equal "jsmith", annotate.revisions[4].author 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 puts "Git test repository NOT FOUND. Skipping unit tests !!!"