15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
|
# File 'lib/bones/plugins/git.rb', line 15
def define_tasks
return unless have? :git
config = ::Bones.config
namespace :git do
task :prereqs
desc 'Show tags from the git repository'
task :tags => 'git:prereqs' do |t|
puts Git.open('.').tags.map {|t| t.name}.reverse
end
desc 'Show all log messages since the last release'
task :changes => 'git:prereqs' do |t|
tag = Git.open('.').tags.map {|t| t.name}.last
range = tag ? "#{tag}..HEAD" : ''
system "git log --oneline #{range}"
end
desc 'Create a new tag in the git repository'
task :create_tag => 'git:prereqs' do |t|
v = ENV['VERSION'] or abort 'Must supply VERSION=x.y.z'
abort "Versions don't match #{v} vs #{config.version}" if v != config.version
git = Git.open '.'
tag = "%s-%s" % [config.name, config.version]
puts "Creating git tag '#{tag}'."
begin
git.add_tag tag
rescue Git::GitExecuteError
abort "Tag creation failed: tag '#{tag}' already exists."
end
if git.remotes.map {|r| r.name}.include? 'origin'
unless system "git push origin #{tag}"
abort "Could not push tag to remote git repository."
end
end
end
desc 'Delete a tag from the git repository'
task :delete_tag => 'git:prereqs' do |t|
v = ENV['VERSION'] or abort 'Must supply VERSION=x.y.z'
git = Git.open '.'
tag = "%s-%s" % [config.name, v]
unless git.tags.map {|t| t.name}.include? tag
puts "Tag '#{tag}' does not exist."
break
end
puts "Deleting git tag '#{tag}'."
abort 'Tag deletion failed.' unless system "git tag -d '#{tag}'"
if git.remotes.map {|r| r.name}.include? 'origin'
unless system "git push origin ':refs/tags/#{tag}'"
abort "Could not delete tag from remote git repository."
end
end
end
end
task 'gem:release' => 'git:create_tag'
end
|