Commit 6a1b17c4 authored by Douwe Maan's avatar Douwe Maan

Merge branch 'fix/gb/make-root-ref-default-instead-of-head' into 'master'

Use root ref instead of HEAD to find latest repository commit

Closes gitlab-ee#5864

See merge request gitlab-org/gitlab-ce!20258
parents 17a38b5a 047ca033
...@@ -99,11 +99,11 @@ class Repository ...@@ -99,11 +99,11 @@ class Repository
"#<#{self.class.name}:#{@disk_path}>" "#<#{self.class.name}:#{@disk_path}>"
end end
def commit(ref = 'HEAD') def commit(ref = nil)
return nil unless exists? return nil unless exists?
return ref if ref.is_a?(::Commit) return ref if ref.is_a?(::Commit)
find_commit(ref) find_commit(ref || root_ref)
end end
# Finding a commit by the passed SHA # Finding a commit by the passed SHA
......
...@@ -479,6 +479,14 @@ describe Repository do ...@@ -479,6 +479,14 @@ describe Repository do
end end
end end
context 'when ref is not specified' do
it 'is using a root ref' do
expect(repository).to receive(:find_commit).with('master')
repository.commit
end
end
context 'when ref is not valid' do context 'when ref is not valid' do
context 'when preceding tree element exists' do context 'when preceding tree element exists' do
it 'returns nil' do it 'returns nil' 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