diff options
-rw-r--r-- | app/models/compare.rb | 5 | ||||
-rw-r--r-- | app/models/merge_request_diff.rb | 7 | ||||
-rw-r--r-- | app/services/compare_service.rb | 7 |
3 files changed, 13 insertions, 6 deletions
diff --git a/app/models/compare.rb b/app/models/compare.rb index 4856510f526..4b568a1d11c 100644 --- a/app/models/compare.rb +++ b/app/models/compare.rb @@ -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 diff --git a/app/models/merge_request_diff.rb b/app/models/merge_request_diff.rb index 3f7e96186a1..0ea9e892be2 100644 --- a/app/models/merge_request_diff.rb +++ b/app/models/merge_request_diff.rb @@ -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 diff --git a/app/services/compare_service.rb b/app/services/compare_service.rb index 6d6075628af..6df3b958b8a 100644 --- a/app/services/compare_service.rb +++ b/app/services/compare_service.rb @@ -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 |