Use straight diff approach when compare merge request versions
Signed-off-by: Dmitriy Zaporozhets <dmitriy.zaporozhets@gmail.com>
This commit is contained in:
parent
c143003bfb
commit
ac4db38094
|
|
@ -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
|
||||
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
||||
|
|
@ -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
|
||||
|
|
|
|||
Loading…
Reference in New Issue