Class: Git::Object::Tag

Inherits:
AbstractObject show all
Defined in:
lib/git/object.rb

Overview

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.

Instance Attribute Summary collapse

Attributes inherited from AbstractObject

#mode, #objectish, #size, #type

Instance Method Summary collapse

Methods inherited from AbstractObject

#archive, #blob?, #commit?, #contents, #contents_array, #diff, #grep, #log, #sha, #to_s, #tree?

Constructor Details

#initialize(base, name) ⇒ Tag #initialize(base, sha, name) ⇒ Tag

Returns a new instance of Tag.

Overloads:

  • #initialize(base, name) ⇒ Tag

    Parameters:

    • base (Git::Repository) —

      the git repository

    • name (String) —

      the name of the tag

  • #initialize(base, sha, name) ⇒ Tag

    Parameters:

    • base (Git::Repository) —

      the git repository

    • sha (String) —

      the SHA of the tag object

    • name (String) —

      the name of the tag



560
561
562
563
564
565
566
567
568
569
570
571
572
# File 'lib/git/object.rb', line 560

def initialize(base, sha, name = nil)
  if name.nil?
    name = sha
    sha = base.tag_sha(name)
    raise Git::UnexpectedResultError, "Tag '#{name}' does not exist." if sha == ''
  end

  super(base, sha)

  @name = name
  @annotated = nil
  @loaded = false
end

Instance Attribute Details

#name ⇒ String

Returns the tag name.

Returns:

  • (String) —

    the tag name



544
545
546
# File 'lib/git/object.rb', line 544

def name
  @name
end

Instance Method Details

#annotated? ⇒ Boolean

Returns whether this tag is annotated

Returns:

  • (Boolean) —

    true when the tag has an annotated tag object



578
579
580
# File 'lib/git/object.rb', line 578

def annotated?
  @annotated = @annotated.nil? ? (object_repository.cat_file_type(name) == 'tag') : @annotated
end

#message ⇒ String?

Returns the tag message

Returns:

  • (String, nil) —

    the annotated tag message, or nil for a lightweight tag



587
588
589
590
# File 'lib/git/object.rb', line 587

def message
  check_tag
  @message
end

#tag? ⇒ Boolean

Returns whether this object is a tag

Returns:

  • (Boolean) —

    true



596
597
598
# File 'lib/git/object.rb', line 596

def tag?
  true
end

#tagger ⇒ Git::AuthorInfo?

Returns the tagger identity

Returns:

  • (Git::AuthorInfo, nil) —

    the tagger for an annotated tag, or nil for a lightweight tag



605
606
607
608
# File 'lib/git/object.rb', line 605

def tagger
  check_tag
  @tagger
end