BigW Consortium Gitlab

Restore diff_sha_refs method

parent 9329436d
......@@ -118,7 +118,11 @@ class DiffNote < Note
end
def noteable_diff_refs
noteable.diff_refs
if noteable.respond_to?(:diff_sha_refs)
noteable.diff_sha_refs
else
noteable.diff_refs
end
end
def set_original_position
......
......@@ -265,28 +265,29 @@ class MergeRequest < ActiveRecord::Base
@source_branch_sha || source_branch_head.try(:sha)
end
def branch_merge_base_sha
branch_merge_base_commit.try(:sha)
def diff_refs
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
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?
merge_request_diff.diff_refs
else
start_sha = target_branch_sha
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
diff_refs
end
end
def branch_merge_base_sha
branch_merge_base_commit.try(:sha)
end
def validate_branches
if target_project == source_project && target_branch == source_branch
errors.add :branch_conflict, "You can not use same project/branch for source and target"
......@@ -748,7 +749,7 @@ class MergeRequest < ActiveRecord::Base
end
def has_complete_diff_refs?
diff_refs && diff_refs.complete?
diff_sha_refs && diff_sha_refs.complete?
end
def update_diff_notes_positions(old_diff_refs:, new_diff_refs:)
......
......@@ -782,7 +782,7 @@ describe MergeRequest, models: true do
end
end
describe "#diff_refs" do
describe "#diff_sha_refs" do
context "with diffs" do
subject { create(:merge_request, :with_diffs) }
......@@ -791,7 +791,7 @@ describe MergeRequest, models: true do
expect_any_instance_of(Repository).not_to receive(:commit)
subject.diff_refs
subject.diff_sha_refs
end
it "returns expected diff_refs" do
......@@ -801,7 +801,7 @@ describe MergeRequest, models: true do
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
......
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