Commit 469d8c66 authored by Patrick Bajao's avatar Patrick Bajao

Stop finding commit with empty ref

When `Projects::RefsController#switch` is requested without `ref`
and `path` params, internally, GitLab still tries to make a
request for `FindCommit` RPC with empty ref.

We don't need to do that as we won't be able to find a commit with
empty ref.
parent e4b4a34b
---
title: Stop finding commit with empty ref
merge_request: 47497
author:
type: fixed
......@@ -68,7 +68,7 @@ module ExtractsRef
raise InvalidPathError if @ref.match?(/\s/)
@commit = @repo.commit(@ref)
@commit = @repo.commit(@ref) if @ref.present?
end
# rubocop:enable Gitlab/ModuleWithInstanceVariables
......
......@@ -112,6 +112,19 @@ RSpec.describe ExtractsPath do
end
end
end
context 'ref and path are nil' do
let(:params) { { path: nil, ref: nil } }
it 'does not set commit' do
expect(container.repository).not_to receive(:commit).with('')
expect(self).to receive(:render_404)
assign_ref_vars
expect(@commit).to be_nil
end
end
end
it_behaves_like 'extracts refs'
......
......@@ -18,6 +18,21 @@ RSpec.describe ExtractsRef do
allow_any_instance_of(described_class).to receive(:repository_container).and_return(container)
end
describe '#assign_ref_vars' do
it_behaves_like 'assigns ref vars'
context 'ref and path are nil' do
let(:params) { { path: nil, ref: nil } }
it 'does not set commit' do
expect(container.repository).not_to receive(:commit).with('')
assign_ref_vars
expect(@commit).to be_nil
end
end
end
it_behaves_like 'extracts refs'
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