File tree 3 files changed +68
-10
lines changed 3 files changed +68
-10
lines changed Original file line number Diff line number Diff line change @@ -408,10 +408,26 @@ def tag(tag_name)
408
408
Git ::Object . new ( self , tag_name , 'tag' , true )
409
409
end
410
410
411
- # creates a new git tag (Git::Tag)
412
- def add_tag ( tag_name )
413
- self . lib . tag ( tag_name )
414
- tag ( tag_name )
411
+ # Creates a new git tag (Git::Tag)
412
+ # Usage:
413
+ # repo.add_tag('tag_name', object_reference)
414
+ # repo.add_tag('tag_name', object_reference, {:options => 'here'})
415
+ # repo.add_tag('tag_name', {:options => 'here'})
416
+ #
417
+ # Options:
418
+ # :a | :annotate -> true
419
+ # :d -> true
420
+ # :m | :message -> String
421
+ # :s -> true
422
+ #
423
+ def add_tag ( name , *opts )
424
+ self . lib . tag ( name , *opts )
425
+ tag ( name )
426
+ end
427
+
428
+ # deletes a tag
429
+ def delete_tag ( name )
430
+ self . lib . tag ( name , { :d => true } )
415
431
end
416
432
417
433
# creates an archive file of the given tree-ish
Original file line number Diff line number Diff line change @@ -562,8 +562,26 @@ def tags
562
562
command_lines ( 'tag' )
563
563
end
564
564
565
- def tag ( tag )
566
- command ( 'tag' , tag )
565
+ def tag ( name , *opts )
566
+ target = opts [ 0 ] . instance_of? ( String ) ? opts [ 0 ] : nil
567
+
568
+ opts = opts . last . instance_of? ( Hash ) ? opts . last : { }
569
+
570
+ if ( opts [ :a ] || opts [ :annotate ] ) && !( opts [ :m ] || opts [ :message ] )
571
+ raise "Can not create an [:a|:annotate] tag without the precense of [:m|:message]."
572
+ end
573
+
574
+ arr_opts = [ ]
575
+
576
+ arr_opts << '-f' if opts [ :force ] || opts [ :f ]
577
+ arr_opts << '-a' if opts [ :a ] || opts [ :annotate ]
578
+ arr_opts << '-s' if opts [ :s ] || opts [ :sign ]
579
+ arr_opts << '-d' if opts [ :d ] || opts [ :delete ]
580
+ arr_opts << name
581
+ arr_opts << target if target
582
+ arr_opts << "-m #{ opts [ :m ] || opts [ :message ] } " if opts [ :m ] || opts [ :message ]
583
+
584
+ command ( 'tag' , arr_opts )
567
585
end
568
586
569
587
Original file line number Diff line number Diff line change @@ -24,12 +24,36 @@ def test_tags
24
24
r1 . commit ( 'my commit' )
25
25
r1 . add_tag ( 'second' )
26
26
27
- assert ( r1 . tags . map { |t | t . name } . include? ( 'first' ) )
27
+ assert ( r1 . tags . any? { |t | t . name == 'first' } )
28
28
29
29
r2 . add_tag ( 'third' )
30
30
31
- assert ( r2 . tags . map { |t | t . name } . include? ( 'third' ) )
32
- assert ( !r2 . tags . map { |t | t . name } . include? ( 'second' ) )
31
+ assert ( r2 . tags . any? { |t | t . name == 'third' } )
32
+ assert ( r2 . tags . none? { |t | t . name == 'second' } )
33
+
34
+ assert_raise RuntimeError do
35
+ r2 . add_tag ( 'fourth' , { :a => true } )
36
+ end
37
+
38
+ r2 . add_tag ( 'fourth' , { :a => true , :m => 'test message' } )
39
+
40
+ assert ( r2 . tags . any? { |t | t . name == 'fourth' } )
41
+
42
+ r2 . add_tag ( 'fifth' , r2 . tags . detect { |t | t . name == 'third' } . objectish )
43
+
44
+ assert ( r2 . tags . detect { |t | t . name == 'third' } . objectish == r2 . tags . detect { |t | t . name == 'fifth' } . objectish )
45
+
46
+ assert_raise Git ::GitExecuteError do
47
+ r2 . add_tag ( 'third' )
48
+ end
49
+
50
+ r2 . add_tag ( 'third' , { :f => true } )
51
+
52
+ r2 . delete_tag ( 'third' )
53
+
54
+ assert_raise Git ::GitTagNameDoesNotExist do
55
+ r2 . tag ( 'third' )
56
+ end
33
57
end
34
58
end
35
- end
59
+ end
You can’t perform that action at this time.
0 commit comments