Commit ff1e0ecf authored by Robert Speicher's avatar Robert Speicher Committed by Robert Speicher

Merge branch 'mr-merge-base' into 'master'

Correctly determine MR diff base when MR has merge conflicts

Fixes https://gitlab.com/gitlab-org/gitlab-ce/issues/12779

See merge request !2632
parent 3d687ec3
Please view this file on the master branch, on stable branches it's out of date. Please view this file on the master branch, on stable branches it's out of date.
v 8.4.3
- Correctly highlight MR diff when MR has merge conflicts
- Fix highlighting in blame view
v 8.4.2 v 8.4.2
- Bump required gitlab-workhorse version to bring in a fix for missing - Bump required gitlab-workhorse version to bring in a fix for missing
artifacts in the build artifacts browser artifacts in the build artifacts browser
...@@ -11,7 +15,6 @@ v 8.4.2 ...@@ -11,7 +15,6 @@ v 8.4.2
track them in Performance Monitoring. track them in Performance Monitoring.
- Increase contrast between highlighted code comments and inline diff marker - Increase contrast between highlighted code comments and inline diff marker
- Fix method undefined when using external commit status in builds - Fix method undefined when using external commit status in builds
- Fix highlighting in blame view.
v 8.4.1 v 8.4.1
- Apply security updates for Rails (4.2.5.1), rails-html-sanitizer (1.0.3), - Apply security updates for Rails (4.2.5.1), rails-html-sanitizer (1.0.3),
......
...@@ -21,7 +21,7 @@ class Projects::CompareController < Projects::ApplicationController ...@@ -21,7 +21,7 @@ class Projects::CompareController < Projects::ApplicationController
@commits = Commit.decorate(compare_result.commits, @project) @commits = Commit.decorate(compare_result.commits, @project)
@diffs = compare_result.diffs @diffs = compare_result.diffs
@commit = @project.commit(head_ref) @commit = @project.commit(head_ref)
@base_commit = @project.commit(base_ref) @base_commit = @project.merge_base_commit(base_ref, head_ref)
@diff_refs = [@base_commit, @commit] @diff_refs = [@base_commit, @commit]
@line_notes = [] @line_notes = []
end end
......
...@@ -183,8 +183,8 @@ class MergeRequest < ActiveRecord::Base ...@@ -183,8 +183,8 @@ class MergeRequest < ActiveRecord::Base
def diff_base_commit def diff_base_commit
if merge_request_diff if merge_request_diff
merge_request_diff.base_commit merge_request_diff.base_commit
else elsif source_sha
self.target_project.commit(self.target_branch) self.target_project.merge_base_commit(self.source_sha, self.target_branch)
end end
end end
...@@ -489,7 +489,7 @@ class MergeRequest < ActiveRecord::Base ...@@ -489,7 +489,7 @@ class MergeRequest < ActiveRecord::Base
end end
def source_sha def source_sha
commits.first.sha last_commit.try(:sha)
end end
def fetch_ref def fetch_ref
......
...@@ -48,14 +48,11 @@ class MergeRequestDiff < ActiveRecord::Base ...@@ -48,14 +48,11 @@ class MergeRequestDiff < ActiveRecord::Base
end end
def diffs_no_whitespace def diffs_no_whitespace
# Get latest sha of branch from source project
source_sha = merge_request.source_project.commit(source_branch).sha
compare_result = Gitlab::CompareResult.new( compare_result = Gitlab::CompareResult.new(
Gitlab::Git::Compare.new( Gitlab::Git::Compare.new(
merge_request.target_project.repository.raw_repository, self.repository.raw_repository,
merge_request.target_branch, self.target_branch,
source_sha, self.source_sha,
), { ignore_whitespace_change: true } ), { ignore_whitespace_change: true }
) )
@diffs_no_whitespace ||= load_diffs(dump_commits(compare_result.diffs)) @diffs_no_whitespace ||= load_diffs(dump_commits(compare_result.diffs))
...@@ -83,8 +80,6 @@ class MergeRequestDiff < ActiveRecord::Base ...@@ -83,8 +80,6 @@ class MergeRequestDiff < ActiveRecord::Base
@last_commit_short_sha ||= last_commit.short_id @last_commit_short_sha ||= last_commit.short_id
end end
private
def dump_commits(commits) def dump_commits(commits)
commits.map(&:to_hash) commits.map(&:to_hash)
end end
...@@ -163,7 +158,7 @@ class MergeRequestDiff < ActiveRecord::Base ...@@ -163,7 +158,7 @@ class MergeRequestDiff < ActiveRecord::Base
self.st_diffs = new_diffs self.st_diffs = new_diffs
self.base_commit_sha = merge_request.target_project.commit(target_branch).try(:sha) self.base_commit_sha = self.repository.merge_base(self.source_sha, self.target_branch)
self.save self.save
end end
...@@ -181,7 +176,10 @@ class MergeRequestDiff < ActiveRecord::Base ...@@ -181,7 +176,10 @@ class MergeRequestDiff < ActiveRecord::Base
merge_request.target_project.repository merge_request.target_project.repository
end end
private def source_sha
source_commit = merge_request.source_project.commit(source_branch)
source_commit.try(:sha)
end
def compare_result def compare_result
@compare_result ||= @compare_result ||=
...@@ -189,15 +187,11 @@ class MergeRequestDiff < ActiveRecord::Base ...@@ -189,15 +187,11 @@ class MergeRequestDiff < ActiveRecord::Base
# Update ref for merge request # Update ref for merge request
merge_request.fetch_ref merge_request.fetch_ref
# Get latest sha of branch from source project
source_commit = merge_request.source_project.commit(source_branch)
source_sha = source_commit.try(:sha)
Gitlab::CompareResult.new( Gitlab::CompareResult.new(
Gitlab::Git::Compare.new( Gitlab::Git::Compare.new(
merge_request.target_project.repository.raw_repository, self.repository.raw_repository,
merge_request.target_branch, self.target_branch,
source_sha, self.source_sha
) )
) )
end end
......
...@@ -344,6 +344,11 @@ class Project < ActiveRecord::Base ...@@ -344,6 +344,11 @@ class Project < ActiveRecord::Base
repository.commit(id) repository.commit(id)
end end
def merge_base_commit(first_commit_id, second_commit_id)
sha = repository.merge_base(first_commit_id, second_commit_id)
repository.commit(sha) if sha
end
def saved? def saved?
id && persisted? id && persisted?
end end
......
...@@ -589,6 +589,8 @@ class Repository ...@@ -589,6 +589,8 @@ class Repository
def merge_base(first_commit_id, second_commit_id) def merge_base(first_commit_id, second_commit_id)
rugged.merge_base(first_commit_id, second_commit_id) rugged.merge_base(first_commit_id, second_commit_id)
rescue Rugged::ReferenceError
nil
end end
def is_ancestor?(ancestor_id, descendant_id) def is_ancestor?(ancestor_id, descendant_id)
......
require 'spec_helper' require 'spec_helper'
describe Ci::Build, models: true do describe Ci::Build, models: true do
let(:project) { FactoryGirl.create :empty_project } let(:project) { FactoryGirl.create :project }
let(:commit) { FactoryGirl.create :ci_commit, project: project } let(:commit) { FactoryGirl.create :ci_commit, project: project }
let(:build) { FactoryGirl.create :ci_build, commit: commit } let(:build) { FactoryGirl.create :ci_build, commit: commit }
......
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