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



554
555
556
557
558
559
560
561
562
563
564
565
566
# File 'lib/git/object.rb', line 554

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

#nameString

Returns the tag name.

Returns:

  • (String)

    the tag name



538
539
540
# File 'lib/git/object.rb', line 538

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



572
573
574
# File 'lib/git/object.rb', line 572

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

#messageString?

Returns the tag message

Returns:

  • (String, nil)

    the annotated tag message, or nil for a lightweight tag



581
582
583
584
# File 'lib/git/object.rb', line 581

def message
  check_tag
  @message
end

#tag?Boolean

Returns whether this object is a tag

Returns:

  • (Boolean)

    true



590
591
592
# File 'lib/git/object.rb', line 590

def tag?
  true
end

#taggerGit::Author?

Returns the tagger identity

Returns:

  • (Git::Author, nil)

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



599
600
601
602
# File 'lib/git/object.rb', line 599

def tagger
  check_tag
  @tagger
end