2018-11-09 13:39:43 -05:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2017-01-04 13:43:06 -05:00
|
|
|
module Gitlab
|
|
|
|
module Git
|
|
|
|
class Ref
|
2017-06-01 17:21:14 -04:00
|
|
|
include Gitlab::EncodingHelper
|
2019-02-21 16:07:26 -05:00
|
|
|
include Gitlab::Git::RuggedImpl::Ref
|
2017-01-04 13:43:06 -05:00
|
|
|
|
|
|
|
# Branch or tag name
|
|
|
|
# without "refs/tags|heads" prefix
|
|
|
|
attr_reader :name
|
|
|
|
|
|
|
|
# Target sha.
|
|
|
|
# Usually it is commit sha but in case
|
|
|
|
# when tag reference on other tag it can be tag sha
|
|
|
|
attr_reader :target
|
|
|
|
|
|
|
|
# Dereferenced target
|
|
|
|
# Commit object to which the Ref points to
|
|
|
|
attr_reader :dereferenced_target
|
|
|
|
|
|
|
|
# Extract branch name from full ref path
|
|
|
|
#
|
|
|
|
# Ex.
|
|
|
|
# Ref.extract_branch_name('refs/heads/master') #=> 'master'
|
|
|
|
def self.extract_branch_name(str)
|
2022-03-29 11:09:53 -04:00
|
|
|
str.delete_prefix('refs/heads/')
|
2017-01-04 13:43:06 -05:00
|
|
|
end
|
|
|
|
|
2018-01-16 16:01:07 -05:00
|
|
|
def initialize(repository, name, target, dereferenced_target)
|
2017-07-14 09:32:01 -04:00
|
|
|
@name = Gitlab::Git.ref_name(name)
|
2018-01-16 16:01:07 -05:00
|
|
|
@dereferenced_target = dereferenced_target
|
2017-01-04 13:43:06 -05:00
|
|
|
@target = if target.respond_to?(:oid)
|
|
|
|
target.oid
|
|
|
|
elsif target.respond_to?(:name)
|
|
|
|
target.name
|
|
|
|
elsif target.is_a? String
|
|
|
|
target
|
|
|
|
else
|
|
|
|
nil
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|