Skip to content

Commit

Permalink
Adding delete_tag
Browse files Browse the repository at this point in the history
Adding support for some `tag` options
  -f
  -d
  -s
  -a
  -m

Supporting `tag` object reference

closes #109
closes #104
closes #24

refs #27
  • Loading branch information
robertodecurnex committed Jan 15, 2014
1 parent 8ed8ba4 commit f5caf77
Show file tree
Hide file tree
Showing 3 changed files with 68 additions and 10 deletions.
24 changes: 20 additions & 4 deletions lib/git/base.rb
Expand Up @@ -408,10 +408,26 @@ def tag(tag_name)
Git::Object.new(self, tag_name, 'tag', true)
end

# creates a new git tag (Git::Tag)
def add_tag(tag_name)
self.lib.tag(tag_name)
tag(tag_name)
# Creates a new git tag (Git::Tag)
# Usage:
# repo.add_tag('tag_name', object_reference)
# repo.add_tag('tag_name', object_reference, {:options => 'here'})
# repo.add_tag('tag_name', {:options => 'here'})
#
# Options:
# :a | :annotate -> true
# :d -> true
# :m | :message -> String
# :s -> true
#
def add_tag(name, *opts)
self.lib.tag(name, *opts)
tag(name)
end

# deletes a tag
def delete_tag(name)
self.lib.tag(name, {:d => true})
end

# creates an archive file of the given tree-ish
Expand Down
22 changes: 20 additions & 2 deletions lib/git/lib.rb
Expand Up @@ -562,8 +562,26 @@ def tags
command_lines('tag')
end

def tag(tag)
command('tag', tag)
def tag(name, *opts)
target = opts[0].instance_of?(String) ? opts[0] : nil

opts = opts.last.instance_of?(Hash) ? opts.last : {}

if (opts[:a] || opts[:annotate]) && !(opts[:m] || opts[:message])
raise "Can not create an [:a|:annotate] tag without the precense of [:m|:message]."
end

arr_opts = []

arr_opts << '-f' if opts[:force] || opts[:f]
arr_opts << '-a' if opts[:a] || opts[:annotate]
arr_opts << '-s' if opts[:s] || opts[:sign]
arr_opts << '-d' if opts[:d] || opts[:delete]
arr_opts << name
arr_opts << target if target
arr_opts << "-m #{opts[:m] || opts[:message]}" if opts[:m] || opts[:message]

command('tag', arr_opts)
end


Expand Down
32 changes: 28 additions & 4 deletions tests/units/test_tags.rb
Expand Up @@ -24,12 +24,36 @@ def test_tags
r1.commit('my commit')
r1.add_tag('second')

assert(r1.tags.map{|t| t.name}.include?('first'))
assert(r1.tags.any?{|t| t.name == 'first'})

r2.add_tag('third')

assert(r2.tags.map{|t| t.name}.include?('third'))
assert(!r2.tags.map{|t| t.name}.include?('second'))
assert(r2.tags.any?{|t| t.name == 'third'})
assert(r2.tags.none?{|t| t.name == 'second'})

assert_raise RuntimeError do
r2.add_tag('fourth', {:a => true})
end

r2.add_tag('fourth', {:a => true, :m => 'test message'})

assert(r2.tags.any?{|t| t.name == 'fourth'})

r2.add_tag('fifth', r2.tags.detect{|t| t.name == 'third'}.objectish)

assert(r2.tags.detect{|t| t.name == 'third'}.objectish == r2.tags.detect{|t| t.name == 'fifth'}.objectish)

assert_raise Git::GitExecuteError do
r2.add_tag('third')
end

r2.add_tag('third', {:f => true})

r2.delete_tag('third')

assert_raise Git::GitTagNameDoesNotExist do
r2.tag('third')
end
end
end
end
end

0 comments on commit f5caf77

Please sign in to comment.