@@ -251,18 +251,36 @@ def check_commit
251251 # Annotated tags contain additional metadata such as the tagger's name, email, and
252252 # the date when the tag was created, along with a message.
253253 #
254+ # TODO: Annotated tags are not objects
255+ #
254256 class Tag < AbstractObject
255257 attr_accessor :name
256258
257- def initialize ( base , sha , name )
259+ # @overload initialize(base, name)
260+ # @param base [Git::Base] The Git base object
261+ # @param name [String] The name of the tag
262+ #
263+ # @overload initialize(base, sha, name)
264+ # @param base [Git::Base] The Git base object
265+ # @param sha [String] The SHA of the tag object
266+ # @param name [String] The name of the tag
267+ #
268+ def initialize ( base , sha , name = nil )
269+ if name . nil?
270+ name = sha
271+ sha = base . lib . tag_sha ( name )
272+ raise Git ::UnexpectedResultError , "Tag '#{ name } ' does not exist." if sha == ''
273+ end
274+
258275 super ( base , sha )
276+
259277 @name = name
260278 @annotated = nil
261279 @loaded = false
262280 end
263281
264282 def annotated?
265- @annotated ||= ( @base . lib . cat_file_type ( name ) == 'tag' )
283+ @annotated = @annotated . nil? ? ( @base . lib . cat_file_type ( name ) == 'tag' ) : @annotated
266284 end
267285
268286 def message
@@ -298,12 +316,10 @@ def check_tag
298316
299317 # if we're calling this, we don't know what type it is yet
300318 # so this is our little factory method
301- def self . new ( base , objectish , type = nil , is_tag = false )
319+ def self . new ( base , objectish , type = nil , is_tag = false ) # rubocop:disable Style/OptionalBooleanParameter
302320 if is_tag
303- sha = base . lib . tag_sha ( objectish )
304- raise Git ::UnexpectedResultError , "Tag '#{ objectish } ' does not exist." if sha == ''
305-
306- return Git ::Object ::Tag . new ( base , sha , objectish )
321+ Git ::Deprecation . warn ( 'Git::Object.new with is_tag argument is deprecated. Use Git::Object::Tag.new instead.' )
322+ return Git ::Object ::Tag . new ( base , objectish )
307323 end
308324
309325 type ||= base . lib . cat_file_type ( objectish )
0 commit comments