Commit b0b5924e authored by Matija Čupić's avatar Matija Čupić

Use nil instead of raising AmbiguousRef

parent 855e7c32
......@@ -36,7 +36,6 @@ class Project < ActiveRecord::Base
extend Gitlab::ConfigHelper
BoardLimitExceeded = Class.new(StandardError)
AmbiguousRef = Class.new(StandardError)
STATISTICS_ATTRIBUTE = 'repositories_count'.freeze
NUMBER_OF_PERMITTED_BOARDS = 1
......@@ -1166,7 +1165,7 @@ class Project < ActiveRecord::Base
branch_exists = repository.branch_exists?(ref)
if tag_exists && branch_exists
raise AmbiguousRef
nil
elsif tag_exists
repository.find_tag(ref)
elsif branch_exists
......@@ -1754,6 +1753,8 @@ class Project < ActiveRecord::Base
def protected_for?(ref)
resolved_ref = resolve_ref(ref)
return false unless resolved_ref
full_ref = resolved_ref.full_ref
ref_name = resolved_ref.name
......
......@@ -17,9 +17,7 @@ module Gitlab
return error('Commit not found')
end
begin
@command.project.resolve_ref(@command.origin_ref)
rescue Project::AmbiguousRef
unless @command.project.resolve_ref(@command.origin_ref)
return error('Ref is ambiguous')
end
end
......
......@@ -2571,6 +2571,14 @@ describe Project do
allow(project).to receive(:resolve_ref).and_return(ref)
end
context 'when ref is ambiguous' do
let(:ref) { nil }
it 'returns false' do
is_expected.to be_falsey
end
end
context 'when the ref is not protected' do
let(:ref) { project.repository.find_branch('master') }
......@@ -2820,8 +2828,8 @@ describe Project do
project.repository.add_branch(project.creator, ref, 'master')
end
it 'raises an error' do
expect { subject }.to raise_error(described_class::AmbiguousRef)
it 'returns nil' do
is_expected.to eq(nil)
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