Commit 94a7198a authored by Dmitriy Zaporozhets's avatar Dmitriy Zaporozhets

Fix merge request diff create and head_commit_sha compatibility

Signed-off-by: default avatarDmitriy Zaporozhets <dmitriy.zaporozhets@gmail.com>
parent 29ac60d7
...@@ -42,8 +42,19 @@ class MergeRequestDiff < ActiveRecord::Base ...@@ -42,8 +42,19 @@ class MergeRequestDiff < ActiveRecord::Base
def ensure_commits_sha def ensure_commits_sha
self.start_commit_sha ||= merge_request.target_branch_sha self.start_commit_sha ||= merge_request.target_branch_sha
self.head_commit_sha ||= last_commit.try(:sha) || merge_request.source_branch_sha self.head_commit_sha ||= merge_request.source_branch_sha
self.base_commit_sha ||= find_base_sha self.base_commit_sha ||= find_base_sha
save
end
# Override head_commit_sha to keep compatibility with merge request diff
# created before version 8.4 that does not store head_commit_sha in separate db field.
def head_commit_sha
if persisted? && super.nil?
last_commit.try(:sha)
else
super
end
end end
# This method will rely on repository branch sha # This method will rely on repository branch sha
...@@ -57,7 +68,7 @@ class MergeRequestDiff < ActiveRecord::Base ...@@ -57,7 +68,7 @@ class MergeRequestDiff < ActiveRecord::Base
# in case head_commit_sha is nil. Its necesarry for old merge request diff # in case head_commit_sha is nil. Its necesarry for old merge request diff
# created before version 8.4 to work # created before version 8.4 to work
def safe_head_commit_sha def safe_head_commit_sha
head_commit_sha || last_commit.try(:sha) || merge_request.source_branch_sha head_commit_sha || merge_request.source_branch_sha
end end
def size def size
...@@ -111,7 +122,7 @@ class MergeRequestDiff < ActiveRecord::Base ...@@ -111,7 +122,7 @@ class MergeRequestDiff < ActiveRecord::Base
end end
def head_commit def head_commit
return last_commit unless head_commit_sha return unless head_commit_sha
project.commit(head_commit_sha) project.commit(head_commit_sha)
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