Class: Bringit::Ref

Inherits:
Object
  • Object
show all
Includes:
EncodingHelper
Defined in:
lib/bringit/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.



41
42
43
44
45
46
47
48
49
50
51
52
53
54
# File 'lib/bringit/ref.rb', line 41

def initialize(repository, name, target)
  encode! name
  @name = name.gsub(/\Arefs\/(tags|heads)\//, '')
  @dereferenced_target = Bringit::Commit.find(repository, target)
  @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

Instance Attribute Details

#dereferenced_targetObject (readonly)

Dereferenced target Commit object to which the Ref points to



25
26
27
# File 'lib/bringit/ref.rb', line 25

def dereferenced_target
  @dereferenced_target
end

#nameObject (readonly)

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



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

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



21
22
23
# File 'lib/bringit/ref.rb', line 21

def target
  @target
end

Class Method Details

.dereference_object(object) ⇒ Object



35
36
37
38
39
# File 'lib/bringit/ref.rb', line 35

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'


31
32
33
# File 'lib/bringit/ref.rb', line 31

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

.name_valid?(name) ⇒ Boolean

Returns:

  • (Boolean)


5
6
7
8
9
10
11
# File 'lib/bringit/ref.rb', line 5

def self.name_valid?(name)
  if name.start_with?('refs/heads/') || name.start_with?('refs/remotes/')
    return false
  end

  Popen.popen(%W(git check-ref-format refs/#{name})).last == 0
end