class TagList
Builds a list of tags in the current git repository. The tags are enclosed by the sha1 of the first commit and optionally “HEAD” to allow traversing the list with each_con to obtain start and end points of developmental epochs.
Attributes
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
Instantiates the tag list.
@param [bool] include_head
Indicates whether or not to include the most recent changes.
# File lib/tag_list.rb, line 31 def initialize(include_head = true) @include_head = include_head @list = build_list end
Public Instance Methods
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_list.rb, line 41 def latest_tag # Index 0 is HEAD # Index 1 is most recent tag or first commit @list[1] end
Private Instance Methods
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_list.rb, line 64 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
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_list.rb, line 55 def get_initial_commit `git rev-list --max-parents=0 HEAD`.chomp end