Class: Gitlab::Git::Ref

Inherits:
Object
  • Object
show all
Includes:
EncodingHelper
Defined in:
lib/gitlab_git/ref.rb

Direct Known Subclasses

Branch, Tag

Constant Summary

Constants included from EncodingHelper

EncodingHelper::ENCODING_CONFIDENCE_THRESHOLD

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods included from EncodingHelper

#encode!, #encode_utf8

Constructor Details

#initialize(repository, name, target) ⇒ Ref

Returns a new instance of Ref.



29
30
31
32
33
34
# File 'lib/gitlab_git/ref.rb', line 29

def initialize(repository, name, target)
  encode! name
  @name = name.gsub(/\Arefs\/(tags|heads)\//, '')

  @target = Commit.find(repository, target)
end

Instance Attribute Details

#nameObject (readonly)

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



8
9
10
# File 'lib/gitlab_git/ref.rb', line 8

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



13
14
15
# File 'lib/gitlab_git/ref.rb', line 13

def target
  @target
end

Class Method Details

.dereference_object(object) ⇒ Object



23
24
25
26
27
# File 'lib/gitlab_git/ref.rb', line 23

def self.dereference_object(object)
  object = object.target while object.is_a?(Rugged::Tag::Annotation)

  object
end

.extract_branch_name(str) ⇒ Object

Extract branch name from full ref path

Ex.

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


19
20
21
# File 'lib/gitlab_git/ref.rb', line 19

def self.extract_branch_name(str)
  str.gsub(/\Arefs\/heads\//, '')
end