diff options
author | Douwe Maan <douwe@gitlab.com> | 2016-11-15 10:22:36 +0000 |
---|---|---|
committer | Douwe Maan <douwe@gitlab.com> | 2016-11-15 10:22:36 +0000 |
commit | fdd7e3f6e93e02adacf283071f88e3284449bb3a (patch) | |
tree | 15dfe31354e0d63cfa5001a797613bcb13391fa0 /lib | |
parent | 3a3b06b4faccaf49279bee397af6df2916a9195e (diff) | |
parent | 0f61bb2dc5298a7e06f8e211adcf46dd282b9c86 (diff) | |
download | gitlab-ce-fdd7e3f6e93e02adacf283071f88e3284449bb3a.tar.gz |
Merge branch 'stanhu/gitlab-ce-fix-error-500-with-mr-images' into 'master'
Fix Error 500 when creating a merge request that contains an image that was deleted and added
_Originally opened at !4816 by @stanhu._
- - -
## What does this MR do?
This MR fixes an Error 500 when creating a merge request that contains an image that was deleted and added. Before, when displaying the before and after image, the code would always retrieve the image from the parent commit. However, in a diff, this could cause two different problems:
The "before" image may not actually be the image you want to compare against (regression of #14327)
It may appear as though a file was modified when it was really just added during the diff
## Are there points in the code the reviewer needs to double check?
There may be a more elegant to fix this bug.
## What are the relevant issue numbers?
Closes #3893, gitlab-org/gitlab-ee#678
See merge request !7457
Diffstat (limited to 'lib')
-rw-r--r-- | lib/gitlab/diff/file.rb | 13 |
1 files changed, 8 insertions, 5 deletions
diff --git a/lib/gitlab/diff/file.rb b/lib/gitlab/diff/file.rb index 5110bfbf898..c6bf25b5874 100644 --- a/lib/gitlab/diff/file.rb +++ b/lib/gitlab/diff/file.rb @@ -55,6 +55,12 @@ module Gitlab repository.commit(deleted_file ? old_ref : new_ref) end + def old_content_commit + return unless diff_refs + + repository.commit(old_ref) + end + def old_ref diff_refs.try(:base_sha) end @@ -111,13 +117,10 @@ module Gitlab diff_lines.count(&:removed?) end - def old_blob(commit = content_commit) + def old_blob(commit = old_content_commit) return unless commit - parent_id = commit.parent_id - return unless parent_id - - repository.blob_at(parent_id, old_path) + repository.blob_at(commit.id, old_path) end def blob(commit = content_commit) |