Commit f65e9677 authored by Dmitriy Zaporozhets's avatar Dmitriy Zaporozhets

Merge branch 'fix-mr-500-error' into 'master'

Fix MergeRequest#new page

* fix 500 error when no parent for initial commit
* fix link from diff files to wrong commit
* fix new file being skipped from diff if it was added in next commit

Fixes #1462

See merge request !998
parents 28151ba5 ddaa493e
...@@ -70,7 +70,7 @@ class Projects::MergeRequestsController < Projects::ApplicationController ...@@ -70,7 +70,7 @@ class Projects::MergeRequestsController < Projects::ApplicationController
@target_project = merge_request.target_project @target_project = merge_request.target_project
@source_project = merge_request.source_project @source_project = merge_request.source_project
@commits = @merge_request.compare_commits @commits = @merge_request.compare_commits
@commit = @merge_request.compare_base_commit @commit = @merge_request.compare_commits.last
@diffs = @merge_request.compare_diffs @diffs = @merge_request.compare_diffs
@note_counts = Note.where(commit_id: @commits.map(&:id)). @note_counts = Note.where(commit_id: @commits.map(&:id)).
group(:commit_id).count group(:commit_id).count
......
...@@ -44,7 +44,7 @@ class MergeRequest < ActiveRecord::Base ...@@ -44,7 +44,7 @@ class MergeRequest < ActiveRecord::Base
# Temporary fields to store compare vars # Temporary fields to store compare vars
# when creating new merge request # when creating new merge request
attr_accessor :can_be_created, :compare_failed, :compare_base_commit, attr_accessor :can_be_created, :compare_failed,
:compare_commits, :compare_diffs :compare_commits, :compare_diffs
ActsAsTaggableOn.strict_case_match = true ActsAsTaggableOn.strict_case_match = true
......
...@@ -263,4 +263,20 @@ class Repository ...@@ -263,4 +263,20 @@ class Repository
contributor contributor
end end
end end
def blob_for_diff(commit, diff)
file = blob_at(commit.id, diff.new_path)
unless file
file = prev_blob_for_diff(commit, diff)
end
file
end
def prev_blob_for_diff(commit, diff)
if commit.parent_id
blob_at(commit.parent_id, diff.old_path)
end
end
end end
...@@ -34,7 +34,6 @@ module MergeRequests ...@@ -34,7 +34,6 @@ module MergeRequests
# If we have at least one commit to merge -> creation allowed # If we have at least one commit to merge -> creation allowed
if commits.present? if commits.present?
merge_request.compare_commits = Commit.decorate(commits) merge_request.compare_commits = Commit.decorate(commits)
merge_request.compare_base_commit = Commit.new(commits.first)
merge_request.can_be_created = true merge_request.can_be_created = true
merge_request.compare_failed = false merge_request.compare_failed = false
......
- file = project.repository.blob_at(@commit.id, diff.new_path) - file = project.repository.blob_for_diff(@commit, diff)
- file = project.repository.blob_at(@commit.parent_id, diff.old_path) unless file
- return unless file - return unless file
.diff-file{id: "diff-#{i}"} .diff-file{id: "diff-#{i}"}
.diff-header{id: "file-path-#{hexdigest(diff.new_path || diff.old_path)}"} .diff-header{id: "file-path-#{hexdigest(diff.new_path || diff.old_path)}"}
...@@ -41,7 +40,7 @@ ...@@ -41,7 +40,7 @@
- else - else
= render "projects/commits/text_file", diff: diff, index: i = render "projects/commits/text_file", diff: diff, index: i
- elsif file.image? - elsif file.image?
- old_file = project.repository.blob_at(@commit.parent_id, diff.old_path) if @commit.parent_id - old_file = project.repository.prev_blob_for_diff(@commit, diff)
= render "projects/commits/image", diff: diff, old_file: old_file, file: file, index: i = render "projects/commits/image", diff: diff, old_file: old_file, file: file, index: i
- else - else
.nothing-here-block No preview for this file type .nothing-here-block No preview for this file type
......
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