summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--app/models/project.rb13
-rw-r--r--app/models/repository.rb4
-rw-r--r--spec/models/repository_spec.rb10
3 files changed, 13 insertions, 14 deletions
diff --git a/app/models/project.rb b/app/models/project.rb
index fa1820b2bdb..a8bef70f505 100644
--- a/app/models/project.rb
+++ b/app/models/project.rb
@@ -1739,12 +1739,13 @@ class Project < ActiveRecord::Base
def protected_for?(ref)
return false if ref.nil? || repository.ambiguous_ref?(ref)
- resolved_ref = repository.resolve_ref(ref)
- ref_name = if resolved_ref == ref
- Gitlab::Git.ref_name(resolved_ref)
- else
- ref
- end
+ if Gitlab::Git.branch_ref?(ref) || Gitlab::Git.tag_ref?(ref)
+ resolved_ref = ref
+ ref_name = Gitlab::Git.ref_name(ref)
+ else
+ resolved_ref = repository.expand_ref(ref)
+ ref_name = ref
+ end
if Gitlab::Git.branch_ref?(resolved_ref)
ProtectedBranch.protected?(self, ref_name)
diff --git a/app/models/repository.rb b/app/models/repository.rb
index 3db49a5fce0..7352386d9d5 100644
--- a/app/models/repository.rb
+++ b/app/models/repository.rb
@@ -186,13 +186,11 @@ class Repository
tag_exists?(ref) && branch_exists?(ref)
end
- def resolve_ref(ref)
+ def expand_ref(ref)
if tag_exists?(ref)
Gitlab::Git::TAG_REF_PREFIX + ref
elsif branch_exists?(ref)
Gitlab::Git::BRANCH_REF_PREFIX + ref
- elsif Gitlab::Git.tag_ref?(ref) || Gitlab::Git.branch_ref?(ref)
- ref
end
end
diff --git a/spec/models/repository_spec.rb b/spec/models/repository_spec.rb
index cdececd49e0..2063b4bbe75 100644
--- a/spec/models/repository_spec.rb
+++ b/spec/models/repository_spec.rb
@@ -1032,16 +1032,16 @@ describe Repository do
end
end
- describe '#resolve_ref' do
+ describe '#expand_ref' do
let(:ref) { 'ref' }
- subject { repository.resolve_ref(ref) }
+ subject { repository.expand_ref(ref) }
- context 'when ref is full ref' do
+ context 'when ref is not tag or branch name' do
let(:ref) { 'refs/heads/master' }
- it 'returns the ref' do
- is_expected.to eq(ref)
+ it 'returns nil' do
+ is_expected.to eq(nil)
end
end