summaryrefslogtreecommitdiff
path: root/app/models
diff options
context:
space:
mode:
authorMatija Čupić <matteeyah@gmail.com>2018-11-09 22:17:43 +0100
committerMatija Čupić <matteeyah@gmail.com>2018-12-08 19:20:22 +0100
commitb278d886ba65e2d3d438352b6243cd33b1ba4636 (patch)
tree47e8740d5983b61fc13f1b513c8f600d7145006d /app/models
parent7cb0dd98590e8fdd7483b9f61643a0daa23c2b67 (diff)
downloadgitlab-ce-b278d886ba65e2d3d438352b6243cd33b1ba4636.tar.gz
Support both ref and ref-name in protected_for?
Diffstat (limited to 'app/models')
-rw-r--r--app/models/project.rb27
1 files changed, 23 insertions, 4 deletions
diff --git a/app/models/project.rb b/app/models/project.rb
index f5dc58cd67f..61840c972ee 100644
--- a/app/models/project.rb
+++ b/app/models/project.rb
@@ -36,6 +36,7 @@ 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
@@ -1160,6 +1161,21 @@ class Project < ActiveRecord::Base
end
end
+ def resolve_ref(ref)
+ tag_exists = repository.tag_exists?(ref)
+ branch_exists = repository.branch_exists?(ref)
+
+ if tag_exists && branch_exists
+ raise AmbiguousRef
+ elsif tag_exists
+ Gitlab::Git::TAG_REF_PREFIX + ref
+ elsif branch_exists
+ Gitlab::Git::BRANCH_REF_PREFIX + ref
+ else
+ ref
+ end
+ end
+
def root_ref?(branch)
repository.root_ref == branch
end
@@ -1737,10 +1753,13 @@ class Project < ActiveRecord::Base
end
def protected_for?(ref)
- if repository.branch_exists?(ref)
- ProtectedBranch.protected?(self, ref)
- elsif repository.tag_exists?(ref)
- ProtectedTag.protected?(self, ref)
+ full_ref = resolve_ref(ref)
+ ref_name = Gitlab::Git.ref_name(full_ref)
+
+ if Gitlab::Git.branch_ref?(full_ref)
+ ProtectedBranch.protected?(self, ref_name)
+ elsif Gitlab::Git.tag_ref?(full_ref)
+ ProtectedTag.protected?(self, ref_name)
end
end