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 ...@@ -68,7 +68,7 @@ module ExtractsRef
raise InvalidPathError if @ref.match?(/\s/) raise InvalidPathError if @ref.match?(/\s/)
@commit = @repo.commit(@ref) @commit = @repo.commit(@ref) if @ref.present?
end end
# rubocop:enable Gitlab/ModuleWithInstanceVariables # rubocop:enable Gitlab/ModuleWithInstanceVariables
......
...@@ -112,6 +112,19 @@ RSpec.describe ExtractsPath do ...@@ -112,6 +112,19 @@ RSpec.describe ExtractsPath do
end end
end 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 end
it_behaves_like 'extracts refs' it_behaves_like 'extracts refs'
......
...@@ -18,6 +18,21 @@ RSpec.describe ExtractsRef do ...@@ -18,6 +18,21 @@ RSpec.describe ExtractsRef do
allow_any_instance_of(described_class).to receive(:repository_container).and_return(container) allow_any_instance_of(described_class).to receive(:repository_container).and_return(container)
end end
describe '#assign_ref_vars' do
it_behaves_like 'assigns ref vars' 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' it_behaves_like 'extracts refs'
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