Read about our upcoming Code of Conduct on this issue

Commit 5cce1278 authored by Douwe Maan's avatar Douwe Maan
Browse files

Correctly determine MR diff base when MR has merge conflicts

parent fe1425084e58
......@@ -20,8 +20,7 @@ v 8.4.2 (unreleased)
improvement when checking if a repository was empty
- Add instrumentation for Gitlab::Git::Repository instance methods so we can
track them in Performance Monitoring.
v 8.4.2 (unreleased)
- Correctly highlight MR diff when MR has merge conflicts
- Fix method undefined when using external commit status in builds
v 8.4.1
......
......@@ -21,7 +21,7 @@ def show
@commits = Commit.decorate(compare_result.commits, @project)
@diffs = compare_result.diffs
@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]
@line_notes = []
end
......
......@@ -184,7 +184,7 @@ def diff_base_commit
if merge_request_diff
merge_request_diff.base_commit
else
self.target_project.commit(self.target_branch)
self.target_project.merge_base_commit(self.source_sha, self.target_branch)
end
end
......@@ -489,7 +489,7 @@ def target_sha
end
def source_sha
commits.first.sha
last_commit.sha
end
def fetch_ref
......
......@@ -48,14 +48,11 @@ def diffs
end
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(
Gitlab::Git::Compare.new(
merge_request.target_project.repository.raw_repository,
merge_request.target_branch,
source_sha,
self.repository.raw_repository,
self.target_branch,
self.source_sha,
), { ignore_whitespace_change: true }
)
@diffs_no_whitespace ||= load_diffs(dump_commits(compare_result.diffs))
......@@ -83,8 +80,6 @@ def last_commit_short_sha
@last_commit_short_sha ||= last_commit.short_id
end
private
def dump_commits(commits)
commits.map(&:to_hash)
end
......@@ -163,7 +158,7 @@ def reload_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
end
......@@ -181,7 +176,10 @@ def repository
merge_request.target_project.repository
end
private
def source_sha
source_commit = merge_request.source_project.commit(source_branch)
source_commit.try(:sha)
end
def compare_result
@compare_result ||=
......@@ -189,15 +187,11 @@ def compare_result
# Update ref for merge request
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::Git::Compare.new(
merge_request.target_project.repository.raw_repository,
merge_request.target_branch,
source_sha,
self.repository.raw_repository,
self.target_branch,
self.source_sha
)
)
end
......
......@@ -348,6 +348,10 @@ def commit(id = 'HEAD')
repository.commit(id)
end
def merge_base_commit(first_commit_id, second_commit_id)
repository.commit(repository.merge_base(first_commit_id, second_commit_id))
end
def saved?
id && persisted?
end
......
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