From 07b9b80a8833cf44ba804c9b8dfdf1550785fe83 Mon Sep 17 00:00:00 2001 From: Lin Jen-Shin Date: Thu, 8 Dec 2016 19:11:52 +0800 Subject: Fix tests to use the new API --- app/services/compare_service.rb | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) (limited to 'app/services/compare_service.rb') diff --git a/app/services/compare_service.rb b/app/services/compare_service.rb index 4367cb5f615..199a015622e 100644 --- a/app/services/compare_service.rb +++ b/app/services/compare_service.rb @@ -3,29 +3,31 @@ 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 - attr_reader :source_project, :source_sha + attr_reader :source_project, :source_branch - def initialize(new_source_project, source_branch) + def initialize(new_source_project, source_branch_name) @source_project = new_source_project - @source_sha = new_source_project.commit(source_branch).try(:sha) + @source_branch = new_source_project.commit(source_branch_name) end def execute(target_project, target_branch, straight: false) + source_sha = source_branch.try(:sha) + return unless source_sha # If compare with other project we need to fetch ref first if target_project == source_project - compare(target_project, target_branch, straight) + compare(source_sha, target_project, target_branch, straight) else target_project.repository.with_tmp_ref(source_project, source_branch) do - compare(target_project, target_branch, straight) + compare(source_sha, target_project, target_branch, straight) end end end private - def compare(target_project, target_branch, straight) + def compare(source_sha, target_project, target_branch, straight) raw_compare = Gitlab::Git::Compare.new( target_project.repository.raw_repository, target_branch, -- cgit v1.2.1