diff --git a/lib/git/diff.rb b/lib/git/diff.rb index d40ddce4..dae7248a 100644 --- a/lib/git/diff.rb +++ b/lib/git/diff.rb @@ -133,6 +133,7 @@ def process_full_diff current_file = Git::EscapedPath.new(m[2]).unescape final[current_file] = defaults.merge({:patch => line, :path => current_file}) else + next unless current_file # Protects against warnings or other garbage output preceeding the diff if m = /^index ([0-9a-f]{4,40})\.\.([0-9a-f]{4,40})( ......)*/.match(line) final[current_file][:src] = m[1] final[current_file][:dst] = m[2] diff --git a/tests/units/test_diff.rb b/tests/units/test_diff.rb index ba21d1f6..ad899b47 100644 --- a/tests/units/test_diff.rb +++ b/tests/units/test_diff.rb @@ -120,5 +120,11 @@ def test_diff_each assert_equal(160, files['scott/newfile'].patch.size) end - + def test_diff_process_full_with_warnings + @diff.send(:cache_full) # prime the cache + warning = "Warning: Permanently added the ECDSA host key for IP address '000.00.000.0' to the list of known hosts.\n" + @diff.instance_variable_set(:@full_diff, warning + @diff.instance_variable_get(:@full_diff)) + + assert_equal('5d46068', @diff["scott/newfile"].src) + end end