diff options
author | Matija Čupić <matteeyah@gmail.com> | 2018-11-15 23:31:02 +0100 |
---|---|---|
committer | Matija Čupić <matteeyah@gmail.com> | 2018-12-08 19:28:34 +0100 |
commit | b0b5924eb418851ddfab848ab16b6acac27d42e0 (patch) | |
tree | 23a7418007019f94923a4a33dbb0ff1c4d4b7461 | |
parent | 855e7c32b9f3541fec085726d338802c8ca9b9f4 (diff) | |
download | gitlab-ce-b0b5924eb418851ddfab848ab16b6acac27d42e0.tar.gz |
Use nil instead of raising AmbiguousRef
-rw-r--r-- | app/models/project.rb | 5 | ||||
-rw-r--r-- | lib/gitlab/ci/pipeline/chain/validate/repository.rb | 4 | ||||
-rw-r--r-- | spec/models/project_spec.rb | 12 |
3 files changed, 14 insertions, 7 deletions
diff --git a/app/models/project.rb b/app/models/project.rb index 6893f76dda9..e1acfbe7770 100644 --- a/app/models/project.rb +++ b/app/models/project.rb @@ -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 diff --git a/lib/gitlab/ci/pipeline/chain/validate/repository.rb b/lib/gitlab/ci/pipeline/chain/validate/repository.rb index 3cec55cdb71..0b411422264 100644 --- a/lib/gitlab/ci/pipeline/chain/validate/repository.rb +++ b/lib/gitlab/ci/pipeline/chain/validate/repository.rb @@ -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 diff --git a/spec/models/project_spec.rb b/spec/models/project_spec.rb index e2e8a76ab72..48cf693b678 100644 --- a/spec/models/project_spec.rb +++ b/spec/models/project_spec.rb @@ -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 |