Skip to content
Snippets Groups Projects
Commit ac4db380 authored by Dmitriy Zaporozhets's avatar Dmitriy Zaporozhets
Browse files

Use straight diff approach when compare merge request versions

parent c143003b
No related branches found
No related tags found
No related merge requests found
Loading
Loading
@@ -11,9 +11,10 @@ class Compare
end
end
 
def initialize(compare, project)
def initialize(compare, project, straight = false)
@compare = compare
@project = project
@straight = straight
end
 
def commits
Loading
Loading
@@ -36,6 +37,8 @@ class Compare
alias_method :commit, :head_commit
 
def base_commit
return start_commit if @straight
return @base_commit if defined?(@base_commit)
 
@base_commit = if start_commit && head_commit
Loading
Loading
Loading
Loading
@@ -167,8 +167,11 @@ class MergeRequestDiff < ActiveRecord::Base
self == merge_request.merge_request_diff
end
 
def compare_with(sha)
CompareService.new.execute(project, head_commit_sha, project, sha)
def compare_with(sha, straight = true)
# When compare merge request versions we want diff A..B instead of A...B
# so we handle cases when user squash and rebase commits in one of versions.
# For this reason we set straight to true by default.
CompareService.new.execute(project, head_commit_sha, project, sha, straight)
end
 
private
Loading
Loading
Loading
Loading
@@ -3,7 +3,7 @@ require 'securerandom'
# Compare 2 branches for one repo or between repositories
# and return Gitlab::Git::Compare object that responds to commits and diffs
class CompareService
def execute(source_project, source_branch, target_project, target_branch)
def execute(source_project, source_branch, target_project, target_branch, straight = false)
source_commit = source_project.commit(source_branch)
return unless source_commit
 
Loading
Loading
@@ -23,9 +23,10 @@ class CompareService
raw_compare = Gitlab::Git::Compare.new(
target_project.repository.raw_repository,
target_branch,
source_sha
source_sha,
straight
)
 
Compare.new(raw_compare, target_project)
Compare.new(raw_compare, target_project, straight)
end
end
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment