Commit 3fa265d1 authored by Adam Niedzielski's avatar Adam Niedzielski

Fix expanding a collapsed diff when converting a symlink to a regular file

In this case comparing old_path and new_path is not enough because there
are two entires that match.
parent e3dcd83d
......@@ -3,7 +3,7 @@ module DiffForPath
def render_diff_for_path(diffs)
diff_file = diffs.diff_files.find do |diff|
diff.old_path == params[:old_path] && diff.new_path == params[:new_path]
diff.file_identifier == params[:file_identifier]
end
return render_404 unless diff_file
......
......@@ -9,7 +9,7 @@
- if !project.repository.diffable?(blob)
.nothing-here-block This diff was suppressed by a .gitattributes entry.
- elsif diff_file.collapsed?
- url = url_for(params.merge(action: :diff_for_path, old_path: diff_file.old_path, new_path: diff_file.new_path))
- url = url_for(params.merge(action: :diff_for_path, old_path: diff_file.old_path, new_path: diff_file.new_path, file_identifier: diff_file.file_identifier))
.nothing-here-block.diff-collapsed{data: { diff_for_path: url } }
This diff is collapsed.
%a.click-to-expand
......
---
title: Fix expanding a collapsed diff when converting a symlink to a regular file
merge_request: 6953
author:
......@@ -126,7 +126,7 @@ module Gitlab
repository.blob_at(commit.id, file_path)
end
def cache_key
def file_identifier
"#{file_path}-#{new_file}-#{deleted_file}-#{renamed_file}"
end
end
......
......@@ -39,7 +39,7 @@ module Gitlab
# hashes that represent serialized diff lines.
#
def cache_highlight!(diff_file)
item_key = diff_file.cache_key
item_key = diff_file.file_identifier
if highlight_cache[item_key]
highlight_diff_file_from_cache!(diff_file, highlight_cache[item_key])
......
......@@ -182,6 +182,20 @@ feature 'Expand and collapse diffs', js: true, feature: true do
end
end
end
context 'expanding a diff when symlink was converted to a regular file' do
let(:branch) { 'symlink-expand-diff' }
it 'shows the content of the regular file' do
expect(page).to have_content('This diff is collapsed')
expect(page).to have_no_content('No longer a symlink')
find('.click-to-expand').click
wait_for_ajax
expect(page).to have_content('No longer a symlink')
end
end
end
context 'visiting a commit without collapsed diffs' do
......
......@@ -23,6 +23,7 @@ module TestEnv
'binary-encoding' => '7b1cf43',
'gitattributes' => '5a62481',
'expand-collapse-diffs' => '4842455',
'symlink-expand-diff' => '81e6355',
'expand-collapse-files' => '025db92',
'expand-collapse-lines' => '238e82d',
'video' => '8879059',
......
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