summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAdam Niedzielski <adamsunday@gmail.com>2016-11-10 18:24:12 +0100
committerAdam Niedzielski <adamsunday@gmail.com>2016-11-10 18:24:12 +0100
commit3fa265d19547669c60788e38e389fa12bb119235 (patch)
treee796b5286824892269c836cb75ce11a479a6472a
parente3dcd83d4a4b75dc050592ea008dc34ecbe0aa49 (diff)
downloadgitlab-ce-adam-fix-collapsed-diff-symlink-file-conversion.tar.gz
Fix expanding a collapsed diff when converting a symlink to a regular fileadam-fix-collapsed-diff-symlink-file-conversion
In this case comparing old_path and new_path is not enough because there are two entires that match.
-rw-r--r--app/controllers/concerns/diff_for_path.rb2
-rw-r--r--app/views/projects/diffs/_content.html.haml2
-rw-r--r--changelogs/unreleased/adam-fix-collapsed-diff-symlink-file-conversion.yml4
-rw-r--r--lib/gitlab/diff/file.rb2
-rw-r--r--lib/gitlab/diff/file_collection/merge_request_diff.rb2
-rw-r--r--spec/features/expand_collapse_diffs_spec.rb14
-rw-r--r--spec/support/test_env.rb1
7 files changed, 23 insertions, 4 deletions
diff --git a/app/controllers/concerns/diff_for_path.rb b/app/controllers/concerns/diff_for_path.rb
index aeec3009f15..1efa9fe060f 100644
--- a/app/controllers/concerns/diff_for_path.rb
+++ b/app/controllers/concerns/diff_for_path.rb
@@ -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
diff --git a/app/views/projects/diffs/_content.html.haml b/app/views/projects/diffs/_content.html.haml
index 779c8ea0104..c3d2f80544b 100644
--- a/app/views/projects/diffs/_content.html.haml
+++ b/app/views/projects/diffs/_content.html.haml
@@ -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
diff --git a/changelogs/unreleased/adam-fix-collapsed-diff-symlink-file-conversion.yml b/changelogs/unreleased/adam-fix-collapsed-diff-symlink-file-conversion.yml
new file mode 100644
index 00000000000..c83558f33d1
--- /dev/null
+++ b/changelogs/unreleased/adam-fix-collapsed-diff-symlink-file-conversion.yml
@@ -0,0 +1,4 @@
+---
+title: Fix expanding a collapsed diff when converting a symlink to a regular file
+merge_request: 6953
+author:
diff --git a/lib/gitlab/diff/file.rb b/lib/gitlab/diff/file.rb
index ce85e5e0123..5110bfbf898 100644
--- a/lib/gitlab/diff/file.rb
+++ b/lib/gitlab/diff/file.rb
@@ -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
diff --git a/lib/gitlab/diff/file_collection/merge_request_diff.rb b/lib/gitlab/diff/file_collection/merge_request_diff.rb
index dc4d47c878b..fe7adb7bed6 100644
--- a/lib/gitlab/diff/file_collection/merge_request_diff.rb
+++ b/lib/gitlab/diff/file_collection/merge_request_diff.rb
@@ -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])
diff --git a/spec/features/expand_collapse_diffs_spec.rb b/spec/features/expand_collapse_diffs_spec.rb
index 6c938bdead8..3934c936f20 100644
--- a/spec/features/expand_collapse_diffs_spec.rb
+++ b/spec/features/expand_collapse_diffs_spec.rb
@@ -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
diff --git a/spec/support/test_env.rb b/spec/support/test_env.rb
index 778e665500d..103f7542286 100644
--- a/spec/support/test_env.rb
+++ b/spec/support/test_env.rb
@@ -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',