diff options
author | James Lopez <james@gitlab.com> | 2019-07-02 08:59:29 +0000 |
---|---|---|
committer | James Lopez <james@gitlab.com> | 2019-07-02 08:59:29 +0000 |
commit | 29b8830bf8ab7cfe37bc0f41066400509fff519f (patch) | |
tree | 37620eca2f221a0ac1b7f2026f5a6f09bf52fb18 | |
parent | bc226cf083c5e2681763955ac1d825bb4542f7d6 (diff) | |
parent | 3d701a7ccc8380ef230357363069d9fb0f5fe574 (diff) | |
download | gitlab-ce-29b8830bf8ab7cfe37bc0f41066400509fff519f.tar.gz |
Merge branch '58808-fix-image-diff-on-text' into 'master'
Don't show image diff note on text file
See merge request gitlab-org/gitlab-ce!30221
-rw-r--r-- | changelogs/unreleased/58808-fix-image-diff-on-text.yml | 5 | ||||
-rw-r--r-- | lib/gitlab/diff/lines_unfolder.rb | 2 | ||||
-rw-r--r-- | spec/lib/gitlab/diff/lines_unfolder_spec.rb | 33 |
3 files changed, 39 insertions, 1 deletions
diff --git a/changelogs/unreleased/58808-fix-image-diff-on-text.yml b/changelogs/unreleased/58808-fix-image-diff-on-text.yml new file mode 100644 index 00000000000..78955c24186 --- /dev/null +++ b/changelogs/unreleased/58808-fix-image-diff-on-text.yml @@ -0,0 +1,5 @@ +--- +title: Don't show image diff note on text file +merge_request: 30221 +author: +type: fixed diff --git a/lib/gitlab/diff/lines_unfolder.rb b/lib/gitlab/diff/lines_unfolder.rb index 6cf904b2b2a..0bd18fe9622 100644 --- a/lib/gitlab/diff/lines_unfolder.rb +++ b/lib/gitlab/diff/lines_unfolder.rb @@ -54,7 +54,7 @@ module Gitlab def unfold_required? strong_memoize(:unfold_required) do next false unless @diff_file.text? - next false unless @position.unchanged? + next false unless @position.on_text? && @position.unchanged? next false if @diff_file.new_file? || @diff_file.deleted_file? next false unless @position.old_line # Invalid position (MR import scenario) diff --git a/spec/lib/gitlab/diff/lines_unfolder_spec.rb b/spec/lib/gitlab/diff/lines_unfolder_spec.rb index 8a470e12d04..3134ff3d817 100644 --- a/spec/lib/gitlab/diff/lines_unfolder_spec.rb +++ b/spec/lib/gitlab/diff/lines_unfolder_spec.rb @@ -842,4 +842,37 @@ describe Gitlab::Diff::LinesUnfolder do end end end + + context 'positioned on an image' do + let(:position) do + Gitlab::Diff::Position.new( + base_sha: '1c59dfa64afbea8c721bb09a06a9d326c952ea19', + start_sha: '1c59dfa64afbea8c721bb09a06a9d326c952ea19', + head_sha: '1487062132228de836236c522fe52fed4980a46c', + old_path: 'image.jpg', + new_path: 'image.jpg', + position_type: 'image' + ) + end + + before do + allow(old_blob).to receive(:binary?).and_return(binary?) + end + + context 'diff file is not text' do + let(:binary?) { true } + + it 'returns nil' do + expect(subject.unfolded_diff_lines).to be_nil + end + end + + context 'diff file is text' do + let(:binary?) { false } + + it 'returns nil' do + expect(subject.unfolded_diff_lines).to be_nil + end + end + end end |