Commit ff128f93 authored by Vasilii Iakliushin's avatar Vasilii Iakliushin

Fix underfined error in Gitlab::Git::Diff

*Problem*

Gitaly::CommitDelta does not have a `#patch` attribute.
It leads to the problem that calls to methods `#too_large?`,
`#collapsed?`, `#has_binary_notice?` and `#to_hash` raise an
exception.

Here is an example of the exception:

```
Failure/Error:
@too_large = @diff.bytesize >= self.class.patch_hard_limit_bytes

NoMethodError:
 undefined method `bytesize' for nil:NilClass
```

*Solution*

I explicitly set `@diff` to have an empty string value if the provided
payload does not implement `#patch` method.
parent d0155a7c
---
title: Fix undefined error in Gitlab::Git::Diff
merge_request: 32967
author:
type: fixed
......@@ -225,7 +225,7 @@ module Gitlab
end
def init_from_gitaly(diff)
@diff = encode!(diff.patch) if diff.respond_to?(:patch)
@diff = diff.respond_to?(:patch) ? encode!(diff.patch) : ''
@new_path = encode!(diff.to_path.dup)
@old_path = encode!(diff.from_path.dup)
@a_mode = diff.old_mode.to_s(8)
......
......@@ -122,6 +122,36 @@ EOT
end
end
end
context 'using a Gitaly::CommitDelta' do
let(:commit_delta) do
Gitaly::CommitDelta.new(
to_path: ".gitmodules",
from_path: ".gitmodules",
old_mode: 0100644,
new_mode: 0100644,
from_id: '357406f3075a57708d0163752905cc1576fceacc',
to_id: '8e5177d718c561d36efde08bad36b43687ee6bf0'
)
end
let(:diff) { described_class.new(commit_delta) }
it 'initializes the diff' do
expect(diff.to_hash).to eq(@raw_diff_hash.merge(diff: ''))
end
it 'is not too large' do
expect(diff).not_to be_too_large
end
it 'has an empty diff' do
expect(diff.diff).to be_empty
end
it 'is not a binary' do
expect(diff).not_to have_binary_notice
end
end
end
describe 'straight diffs' do
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment