Class: Git::Object::Tag Deprecated

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

Overview

Deprecated.

Use Repository::ObjectOperations#tag_list and TagInfo instead

TagInfo is an immutable value object carrying the tag's name, oid, target_oid, annotated?, message, and tagger. Call the corresponding 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.

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

    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. TagInfo describes a ref, so there is no OID-based replacement for this form: pass sha to the Repository operation directly, or read the tag object with Repository::ObjectOperations#cat_file_tag.

    Parameters:

    • base (Git::Repository)

      the git repository

    • sha (String)

      the SHA of the tag object

    • name (String)

      the name of the tag



579
580
581
582
583
584
585
586
587
588
589
590
# 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

Instance Attribute Details

#nameString

Returns the tag name.

Returns:

  • (String)

    the tag name



556
557
558
# File 'lib/git/object.rb', line 556

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



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

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



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

def message
  check_tag
  @message
end

#tag?Boolean

Returns whether this object is a tag

Returns:

  • (Boolean)

    true



614
615
616
# File 'lib/git/object.rb', line 614

def tag?
  true
end

#taggerGit::AuthorInfo?

Returns the tagger identity

Returns:

  • (Git::AuthorInfo, nil)

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



623
624
625
626
# File 'lib/git/object.rb', line 623

def tagger
  check_tag
  @tagger
end