Commit a16dc5cd authored by Alejandro Rodríguez's avatar Alejandro Rodríguez

Ensure Rugged methods are called with a Rugged Commit

parent 89969d0a
...@@ -763,7 +763,7 @@ class Repository ...@@ -763,7 +763,7 @@ class Repository
index = Gitlab::Git::Index.new(raw_repository) index = Gitlab::Git::Index.new(raw_repository)
if start_commit if start_commit
index.read_tree(start_commit.raw_commit.tree) index.read_tree(start_commit.rugged_commit.tree)
parents = [start_commit.sha] parents = [start_commit.sha]
else else
parents = [] parents = []
......
...@@ -77,8 +77,8 @@ EOM ...@@ -77,8 +77,8 @@ EOM
def initialize(merge_request, project) def initialize(merge_request, project)
@merge_request = merge_request @merge_request = merge_request
@our_commit = merge_request.source_branch_head.raw.raw_commit @our_commit = merge_request.source_branch_head.raw.rugged_commit
@their_commit = merge_request.target_branch_head.raw.raw_commit @their_commit = merge_request.target_branch_head.raw.rugged_commit
@project = project @project = project
end end
end end
......
...@@ -14,7 +14,7 @@ module Gitlab ...@@ -14,7 +14,7 @@ module Gitlab
attr_accessor *SERIALIZE_KEYS # rubocop:disable Lint/AmbiguousOperator attr_accessor *SERIALIZE_KEYS # rubocop:disable Lint/AmbiguousOperator
delegate :tree, to: :raw_commit delegate :tree, to: :rugged_commit
def ==(other) def ==(other)
return false unless other.is_a?(Gitlab::Git::Commit) return false unless other.is_a?(Gitlab::Git::Commit)
...@@ -287,7 +287,7 @@ module Gitlab ...@@ -287,7 +287,7 @@ module Gitlab
# empty repo. See Repository#diff for keys allowed in the +options+ # empty repo. See Repository#diff for keys allowed in the +options+
# hash. # hash.
def diff_from_parent(options = {}) def diff_from_parent(options = {})
Commit.diff_from_parent(raw_commit, options) Commit.diff_from_parent(rugged_commit, options)
end end
def deltas def deltas
...@@ -335,7 +335,7 @@ module Gitlab ...@@ -335,7 +335,7 @@ module Gitlab
def to_patch(options = {}) def to_patch(options = {})
begin begin
raw_commit.to_mbox(options) rugged_commit.to_mbox(options)
rescue Rugged::InvalidError => ex rescue Rugged::InvalidError => ex
if ex.message =~ /commit \w+ is a merge commit/i if ex.message =~ /commit \w+ is a merge commit/i
'Patch format is not currently supported for merge commits.' 'Patch format is not currently supported for merge commits.'
...@@ -383,6 +383,14 @@ module Gitlab ...@@ -383,6 +383,14 @@ module Gitlab
encode! @committer_email encode! @committer_email
end end
def rugged_commit
@rugged_commit ||= if raw_commit.is_a?(Rugged::Commit)
raw_commit
else
@repository.rev_parse_target(id)
end
end
private private
def init_from_hash(hash) def init_from_hash(hash)
......
...@@ -6,7 +6,7 @@ require Rails.root.join('db', 'migrate', '20161124141322_migrate_process_commit_ ...@@ -6,7 +6,7 @@ require Rails.root.join('db', 'migrate', '20161124141322_migrate_process_commit_
describe MigrateProcessCommitWorkerJobs do describe MigrateProcessCommitWorkerJobs do
let(:project) { create(:project, :repository) } let(:project) { create(:project, :repository) }
let(:user) { create(:user) } let(:user) { create(:user) }
let(:commit) { project.commit.raw.raw_commit } let(:commit) { project.commit.raw.rugged_commit }
describe 'Project' do describe 'Project' do
describe 'find_including_path' do describe 'find_including_path' do
......
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