Commit eb355dec authored by Dmitriy Zaporozhets's avatar Dmitriy Zaporozhets

Restore diff_sha_refs method

Signed-off-by: default avatarDmitriy Zaporozhets <dmitriy.zaporozhets@gmail.com>
parent 9329436d
...@@ -118,7 +118,11 @@ class DiffNote < Note ...@@ -118,7 +118,11 @@ class DiffNote < Note
end end
def noteable_diff_refs def noteable_diff_refs
noteable.diff_refs if noteable.respond_to?(:diff_sha_refs)
noteable.diff_sha_refs
else
noteable.diff_refs
end
end end
def set_original_position def set_original_position
......
...@@ -265,28 +265,29 @@ class MergeRequest < ActiveRecord::Base ...@@ -265,28 +265,29 @@ class MergeRequest < ActiveRecord::Base
@source_branch_sha || source_branch_head.try(:sha) @source_branch_sha || source_branch_head.try(:sha)
end end
def branch_merge_base_sha def diff_refs
branch_merge_base_commit.try(:sha) return unless diff_start_commit || diff_base_commit
Gitlab::Diff::DiffRefs.new(
base_sha: diff_base_sha,
start_sha: diff_start_sha,
head_sha: diff_head_sha
)
end end
def diff_refs # Return diff_refs instance trying to not touch the git repository
def diff_sha_refs
if merge_request_diff && merge_request_diff.diff_refs_by_sha? if merge_request_diff && merge_request_diff.diff_refs_by_sha?
merge_request_diff.diff_refs merge_request_diff.diff_refs
else else
start_sha = target_branch_sha diff_refs
head_sha = source_branch_sha
base_sha = branch_merge_base_sha
if start_sha || base_sha
Gitlab::Diff::DiffRefs.new(
base_sha: base_sha,
start_sha: start_sha,
head_sha: head_sha
)
end
end end
end end
def branch_merge_base_sha
branch_merge_base_commit.try(:sha)
end
def validate_branches def validate_branches
if target_project == source_project && target_branch == source_branch if target_project == source_project && target_branch == source_branch
errors.add :branch_conflict, "You can not use same project/branch for source and target" errors.add :branch_conflict, "You can not use same project/branch for source and target"
...@@ -748,7 +749,7 @@ class MergeRequest < ActiveRecord::Base ...@@ -748,7 +749,7 @@ class MergeRequest < ActiveRecord::Base
end end
def has_complete_diff_refs? def has_complete_diff_refs?
diff_refs && diff_refs.complete? diff_sha_refs && diff_sha_refs.complete?
end end
def update_diff_notes_positions(old_diff_refs:, new_diff_refs:) def update_diff_notes_positions(old_diff_refs:, new_diff_refs:)
......
...@@ -782,7 +782,7 @@ describe MergeRequest, models: true do ...@@ -782,7 +782,7 @@ describe MergeRequest, models: true do
end end
end end
describe "#diff_refs" do describe "#diff_sha_refs" do
context "with diffs" do context "with diffs" do
subject { create(:merge_request, :with_diffs) } subject { create(:merge_request, :with_diffs) }
...@@ -791,7 +791,7 @@ describe MergeRequest, models: true do ...@@ -791,7 +791,7 @@ describe MergeRequest, models: true do
expect_any_instance_of(Repository).not_to receive(:commit) expect_any_instance_of(Repository).not_to receive(:commit)
subject.diff_refs subject.diff_sha_refs
end end
it "returns expected diff_refs" do it "returns expected diff_refs" do
...@@ -801,7 +801,7 @@ describe MergeRequest, models: true do ...@@ -801,7 +801,7 @@ describe MergeRequest, models: true do
head_sha: subject.merge_request_diff.head_commit_sha head_sha: subject.merge_request_diff.head_commit_sha
) )
expect(subject.diff_refs).to eq(expected_diff_refs) expect(subject.diff_sha_refs).to eq(expected_diff_refs)
end end
end end
end 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