class Pkg::Util::Git_tag

Constants

DEVNULL
GIT
SHA1

A SHA1 sum is 20 characters long, but Git will match on the first ~8 or so. And 8 is long enough for fun test sums like 'cafebeef' or 'deadfeed`.

Attributes

address[R]
branch_name[R]
ref[R]
ref_name[R]
ref_type[R]

Public Class Methods

new(address, reference) click to toggle source
# File lib/packaging/util/git_tags.rb, line 13
def initialize(address, reference)
  @address = address
  @ref = reference
  parse_ref!
end

Public Instance Methods

branch?() click to toggle source
# File lib/packaging/util/git_tags.rb, line 61
def branch?
  ref_type.downcase == "heads"
end
fetch_full_ref() click to toggle source

Fetch the full ref using ls-remote, this should raise an error if it returns non-zero because that means this ref doesn't exist in the repo

# File lib/packaging/util/git_tags.rb, line 45
def fetch_full_ref
  stdout, _, _ = Pkg::Util::Execution.capture3("#{GIT} ls-remote --tags --heads --exit-code #{address} #{ref}")
  stdout.split.last
rescue RuntimeError => e
  raise "ERROR : Not a ref or sha!\n#{e}"
end
parse_ref!() click to toggle source

Parse ref in one of three ways: if the ref is already in a good format just grab the ref type from the string. if it's not, check if it's a sha, if that is true then list it as a sha. finally if it's neither of those fetch the full ref and parse that.

# File lib/packaging/util/git_tags.rb, line 23
def parse_ref!
  if ref?
    split_ref(ref)
  elsif sha?
    @ref_type = "sha"
  else
    split_ref(fetch_full_ref)
  end
end
ref?() click to toggle source
# File lib/packaging/util/git_tags.rb, line 56
def ref?
  `#{GIT} check-ref-format #{ref} >#{DEVNULL} 2>&1`
  $?.success?
end
sha?() click to toggle source
# File lib/packaging/util/git_tags.rb, line 69
def sha?
  !!(ref =~ SHA1)
end
split_ref(ref) click to toggle source

Split the ref based on slashes, set ref_name and ref_type based on the last two items from the split. i.e. refs/tags/1.1.1 would return:

@ref_name => 1.1.1       @ref_type => tags
# File lib/packaging/util/git_tags.rb, line 36
def split_ref(ref)
  ref_parts = ref.split('/', 3)
  @ref_name = ref_parts.pop
  @ref_type = ref_parts.pop
  [@ref_type, @ref_name]
end
tag?() click to toggle source
# File lib/packaging/util/git_tags.rb, line 65
def tag?
  ref_type.downcase == "tags"
end