Skip to content

Proof of concept fix for git diff parsing failure on warn [Issue #574] #585

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
Proof of concept fix for git diff parsing failure on warn
Signed-off-by: Drew Long <drew@taskrabbit.com>
  • Loading branch information
aalong-tr committed Jun 14, 2022
commit b7da9ab833088c572bae363b80ef4ed8a0baf956
1 change: 1 addition & 0 deletions lib/git/diff.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down
8 changes: 7 additions & 1 deletion tests/units/test_diff.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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