Skip to content

Commit b7da9ab

Browse files
committed
Proof of concept fix for git diff parsing failure on warn
Signed-off-by: Drew Long <drew@taskrabbit.com>
1 parent 6f2b3fd commit b7da9ab

File tree

2 files changed

+8
-1
lines changed

2 files changed

+8
-1
lines changed

lib/git/diff.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -133,6 +133,7 @@ def process_full_diff
133133
current_file = Git::EscapedPath.new(m[2]).unescape
134134
final[current_file] = defaults.merge({:patch => line, :path => current_file})
135135
else
136+
next unless current_file # Protects against warnings or other garbage output preceeding the diff
136137
if m = /^index ([0-9a-f]{4,40})\.\.([0-9a-f]{4,40})( ......)*/.match(line)
137138
final[current_file][:src] = m[1]
138139
final[current_file][:dst] = m[2]

tests/units/test_diff.rb

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -120,5 +120,11 @@ def test_diff_each
120120
assert_equal(160, files['scott/newfile'].patch.size)
121121
end
122122

123-
123+
def test_diff_process_full_with_warnings
124+
@diff.send(:cache_full) # prime the cache
125+
warning = "Warning: Permanently added the ECDSA host key for IP address '000.00.000.0' to the list of known hosts.\n"
126+
@diff.instance_variable_set(:@full_diff, warning + @diff.instance_variable_get(:@full_diff))
127+
128+
assert_equal('5d46068', @diff["scott/newfile"].src)
129+
end
124130
end

0 commit comments

Comments
 (0)