Commit 6316a420 authored by Patrick Bajao's avatar Patrick Bajao

Merge branch...

Merge branch '334273-when-not-showing-whitespace-changes-renamed-files-are-not-properly-identified-in-mr-diffs' into 'master'

Resolve "When not showing whitespace changes, renamed files are not properly identified in MR Diffs"

See merge request gitlab-org/gitlab!66873
parents abad6679 89a8c4f9
...@@ -395,10 +395,10 @@ class MergeRequestDiff < ApplicationRecord ...@@ -395,10 +395,10 @@ class MergeRequestDiff < ApplicationRecord
if comparison if comparison
if diff_options[:paths].blank? && !without_files? if diff_options[:paths].blank? && !without_files?
# Return the empty MergeRequestDiffBatch for an out of bound batch request # Return the empty MergeRequestDiffBatch for an out of bound batch request
break diffs_batch if diffs_batch.diff_file_paths.blank? break diffs_batch if diffs_batch.diff_paths.blank?
diff_options.merge!( diff_options.merge!(
paths: diffs_batch.diff_file_paths, paths: diffs_batch.diff_paths,
pagination_data: diffs_batch.pagination_data pagination_data: diffs_batch.pagination_data
) )
end end
......
...@@ -43,10 +43,16 @@ module Gitlab ...@@ -43,10 +43,16 @@ module Gitlab
end end
end end
# This is either the new path, otherwise the old path for the diff_file
def diff_file_paths def diff_file_paths
diff_files.map(&:file_path) diff_files.map(&:file_path)
end end
# This is both the new and old paths for the diff_file
def diff_paths
diff_files.map(&:paths).flatten.uniq
end
def pagination_data def pagination_data
@pagination_data || empty_pagination_data @pagination_data || empty_pagination_data
end end
......
...@@ -465,11 +465,13 @@ RSpec.describe MergeRequestDiff do ...@@ -465,11 +465,13 @@ RSpec.describe MergeRequestDiff do
it 'sorts diff files directory first' do it 'sorts diff files directory first' do
diff_with_commits.update!(sorted: false) # Mark as unsorted so it'll re-order diff_with_commits.update!(sorted: false) # Mark as unsorted so it'll re-order
expect(diff_with_commits.diffs_in_batch(0, 10, diff_options: diff_options).diff_file_paths).to eq([ # There will be 11 returned, as we have to take into account for new and old paths
expect(diff_with_commits.diffs_in_batch(0, 10, diff_options: diff_options).diff_paths).to eq([
'bar/branch-test.txt', 'bar/branch-test.txt',
'custom-highlighting/test.gitlab-custom', 'custom-highlighting/test.gitlab-custom',
'encoding/iso8859.txt', 'encoding/iso8859.txt',
'files/images/wm.svg', 'files/images/wm.svg',
'files/js/commit.js.coffee',
'files/js/commit.coffee', 'files/js/commit.coffee',
'files/lfs/lfs_object.iso', 'files/lfs/lfs_object.iso',
'files/ruby/popen.rb', 'files/ruby/popen.rb',
...@@ -553,11 +555,12 @@ RSpec.describe MergeRequestDiff do ...@@ -553,11 +555,12 @@ RSpec.describe MergeRequestDiff do
it 'sorts diff files directory first' do it 'sorts diff files directory first' do
diff_with_commits.update!(sorted: false) # Mark as unsorted so it'll re-order diff_with_commits.update!(sorted: false) # Mark as unsorted so it'll re-order
expect(diff_with_commits.diffs(diff_options).diff_file_paths).to eq([ expect(diff_with_commits.diffs(diff_options).diff_paths).to eq([
'bar/branch-test.txt', 'bar/branch-test.txt',
'custom-highlighting/test.gitlab-custom', 'custom-highlighting/test.gitlab-custom',
'encoding/iso8859.txt', 'encoding/iso8859.txt',
'files/images/wm.svg', 'files/images/wm.svg',
'files/js/commit.js.coffee',
'files/js/commit.coffee', 'files/js/commit.coffee',
'files/lfs/lfs_object.iso', 'files/lfs/lfs_object.iso',
'files/ruby/popen.rb', 'files/ruby/popen.rb',
......
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