class Git::TagList

Attributes

list[R]

Returns an array of tag names surrounded by HEAD at the top and the sha1 of the first commit at the bottom.

Public Class Methods

new(include_head = true) click to toggle source

Instantiates the tag list.

@param [bool] include_head

Indicates whether or not to include the most recent changes.
# File lib/tag_changelog/git/tag_list.rb, line 32
def initialize(include_head = true)
  @include_head = include_head
  @list = build_list
end

Public Instance Methods

latest_tag() click to toggle source

Returns the most recent tag in the git repository, or the sha1 of the initial commit if there is no tag.

@return [String]

# File lib/tag_changelog/git/tag_list.rb, line 42
def latest_tag
  # Index 0 is HEAD
  # Index 1 is most recent tag or first commit
  @list[1]
end

Private Instance Methods

build_list() click to toggle source

Builds a list of Git tags and encloses it with HEAD and the Sha-1 of the initial commit.

@return [Array]

Array of tags, surrounded by HEAD and the Sha-1 of the initial commit.
# File lib/tag_changelog/git/tag_list.rb, line 65
def build_list
  tags = []
  tags <<  get_initial_commit
  tags += `git tag --sort v:refname`.split("\n").map { |s| s.rstrip }
  tags << "HEAD" if @include_head
  tags.reverse
end
get_initial_commit() click to toggle source

Returns the sha1 of the initial commit. In fact, this function returns all parentless commits of the repository. Usually there should be not more than one such commit. See stackoverflow.com/a/1007545/270712

# File lib/tag_changelog/git/tag_list.rb, line 56
def get_initial_commit
  `git rev-list --max-parents=0 HEAD`.chomp
end