class Git::Object::AbstractObject::Tag
A Git tag object
This class represents a tag in Git, which can be either annotated or lightweight.
Annotated tags contain additional metadata such as the tagger’s name, email, and the date when the tag was created, along with a message.
@deprecated Use {Git::Repository::ObjectOperations#tag_list} and
{Git::TagInfo} instead
{Git::TagInfo} is an immutable value object carrying the tag's `name`,
`oid`, `target_oid`, `annotated?`, `message`, and `tagger`. Call the
corresponding {Git::Repository} method (e.g. `archive`, `log`, `diff`,
`cat_file_contents`) with `info.oid || info.target_oid` for operations
on a tag; that is the object this class resolves and pins at
construction, so a later move of the tag does not redirect an existing
object, whereas the tag name would. Constructing a `Git::Object::Tag`
emits a deprecation warning.
Attributes
@return [String] the tag name
Public Class Methods
Source
# File lib/git/object.rb, line 579 def initialize(base, sha, name = nil) Git::Deprecation.warn( 'Git::Object::Tag is deprecated and will be removed in v6.0.0. ' \ 'Use Git::Repository#tag_list and Git::TagInfo instead.' ) sha, name = resolve_sha_and_name(base, sha, name) super(base, sha) @name = name @annotated = nil @loaded = false end
@overload initialize(base, name)
@param base [Git::Repository] the git repository @param name [String] the name of the tag
@overload initialize(base, sha, name)
`sha` is kept as the object that the inherited operations (`size`,
`contents`, `grep`, `diff`, `log`, `archive`) run against; `annotated?`,
`message`, and `tagger` read the ref `name`. {Git::TagInfo} describes a
ref, so there is no OID-based replacement for this form: pass `sha` to
the {Git::Repository} operation directly, or read the tag object with
{Git::Repository::ObjectOperations#cat_file_tag}.
@param base [Git::Repository] the git repository
@param sha [String] the SHA of the tag object
@param name [String] the name of the tag
Git::Object::AbstractObject::new
Public Instance Methods
Source
# File lib/git/object.rb, line 596 def annotated? @annotated = @annotated.nil? ? (object_repository.cat_file_type(name) == 'tag') : @annotated end
Returns whether this tag is annotated
@return [Boolean] ‘true` when the tag has an annotated tag object
Source
# File lib/git/object.rb, line 605 def message check_tag @message end
Returns the tag message
@return [String, nil] the annotated tag message, or ‘nil` for a
lightweight tag
Source
# File lib/git/object.rb, line 614 def tag? true end
Returns whether this object is a tag
@return [Boolean] ‘true`
Source
# File lib/git/object.rb, line 623 def tagger check_tag @tagger end
Returns the tagger identity
@return [Git::AuthorInfo, nil] the tagger for an annotated tag, or ‘nil`
for a lightweight tag
Private Instance Methods
Source
# File lib/git/object.rb, line 659 def check_tag return if @loaded if annotated? tdata = object_repository.cat_file_tag(@name) @message = tdata['message'].chomp @tagger = Git::AuthorInfo.parse(tdata['tagger']) else @message = @tagger = nil end @loaded = true end
Loads annotated tag data when available
@return [void]
Source
# File lib/git/object.rb, line 646 def resolve_sha_and_name(base, sha, name) return [sha, name] unless name.nil? resolved = base.tag_sha(sha) raise Git::UnexpectedResultError, "Tag '#{sha}' does not exist." if resolved == '' [resolved, sha] end
Resolves the two-argument constructor form to a SHA and a tag name
In the two-argument form ‘sha` carries the tag name and the SHA is looked up from the repository.
@param base [Git::Repository] the git repository
@param sha [String] the SHA of the tag object, or the tag name in the
two-argument form
@param name [String, nil] the tag name, or ‘nil` in the two-argument form
@return [Array(String, String)] the resolved ‘[sha, name]` pair
@raise [Git::UnexpectedResultError] if the tag does not exist