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