Class: Gitlab::Git::Ref

Inherits:
Object
  • Object
show all
Includes:
EncodingHelper, Gitlab::Git::RuggedImpl::Ref
Defined in:
lib/gitlab/git/ref.rb

Direct Known Subclasses

Branch, Tag

Constant Summary

Constants included from EncodingHelper

EncodingHelper::BOM_UTF8, EncodingHelper::ENCODING_CONFIDENCE_THRESHOLD, EncodingHelper::ESCAPED_CHARS, EncodingHelper::UNICODE_REPLACEMENT_CHARACTER

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Gitlab::Git::RuggedImpl::Ref

dereference_object

Methods included from EncodingHelper

#binary_io, #detect_binary?, #detect_encoding, #detect_libgit2_binary?, #encode!, #encode_binary, #encode_utf8, #encode_utf8_no_detect, #encode_utf8_with_escaping!, #encode_utf8_with_replacement_character, #strip_bom, #unquote_path

Constructor Details

#initialize(repository, name, target, dereferenced_target) ⇒ Ref

Returns a new instance of Ref.



30
31
32
33
34
35
36
37
38
39
40
# File 'lib/gitlab/git/ref.rb', line 30

def initialize(repository, name, target, dereferenced_target)
  @name = Gitlab::Git.ref_name(name)
  @dereferenced_target = dereferenced_target
  @target = if target.respond_to?(:oid)
              target.oid
            elsif target.respond_to?(:name)
              target.name
            elsif target.is_a? String
              target
            end
end

Instance Attribute Details

#dereferenced_targetObject (readonly)

Dereferenced target Commit object to which the Ref points to



20
21
22
# File 'lib/gitlab/git/ref.rb', line 20

def dereferenced_target
  @dereferenced_target
end

#nameObject (readonly)

Branch or tag name without “refs/tags|heads” prefix



11
12
13
# File 'lib/gitlab/git/ref.rb', line 11

def name
  @name
end

#targetObject (readonly)

Target sha. Usually it is commit sha but in case when tag reference on other tag it can be tag sha



16
17
18
# File 'lib/gitlab/git/ref.rb', line 16

def target
  @target
end

Class Method Details

.extract_branch_name(str) ⇒ Object

Extract branch name from full ref path

Ex.

Ref.extract_branch_name('refs/heads/master') #=> 'master'


26
27
28
# File 'lib/gitlab/git/ref.rb', line 26

def self.extract_branch_name(str)
  str.delete_prefix('refs/heads/')
end