summaryrefslogtreecommitdiff
path: root/lib/extracts_ref.rb
diff options
context:
space:
mode:
authorGitLab Release Tools Bot <delivery-team+release-tools@gitlab.com>2023-03-30 21:24:47 +0000
committerGitLab Release Tools Bot <delivery-team+release-tools@gitlab.com>2023-03-30 21:24:47 +0000
commit9025d53443ae9708675aaa5b035fdb79562bebad (patch)
treebb4f5ba0c7d4e5c206cd37e7e59f062ed6df685d /lib/extracts_ref.rb
parentc00b0b2dedd4748d8f2d44c70c954d39e37d4696 (diff)
parentc57c04a970e6e1afcd0dbc287afe1006a103afd4 (diff)
downloadgitlab-ce-9025d53443ae9708675aaa5b035fdb79562bebad.tar.gz
Merge remote-tracking branch 'dev/15-8-stable' into 15-8-stable
Diffstat (limited to 'lib/extracts_ref.rb')
-rw-r--r--lib/extracts_ref.rb14
1 files changed, 12 insertions, 2 deletions
diff --git a/lib/extracts_ref.rb b/lib/extracts_ref.rb
index f22996df0a5..23f93ad1317 100644
--- a/lib/extracts_ref.rb
+++ b/lib/extracts_ref.rb
@@ -5,7 +5,8 @@
# Can be extended for different types of repository object, e.g. Project or Snippet
module ExtractsRef
InvalidPathError = Class.new(StandardError)
-
+ BRANCH_REF_TYPE = 'heads'
+ TAG_REF_TYPE = 'tags'
# Given a string containing both a Git tree-ish, such as a branch or tag, and
# a filesystem path joined by forward slashes, attempts to separate the two.
#
@@ -91,7 +92,7 @@ module ExtractsRef
def ref_type
return unless params[:ref_type].present?
- params[:ref_type] == 'tags' ? 'tags' : 'heads'
+ params[:ref_type] == TAG_REF_TYPE ? TAG_REF_TYPE : BRANCH_REF_TYPE
end
private
@@ -154,4 +155,13 @@ module ExtractsRef
def repository_container
raise NotImplementedError
end
+
+ def ambiguous_ref?(project, ref)
+ return true if project.repository.ambiguous_ref?(ref)
+
+ return false unless ref&.starts_with?('refs/')
+
+ unprefixed_ref = ref.sub(%r{^refs/(heads|tags)/}, '')
+ project.repository.commit(unprefixed_ref).present?
+ end
end