Skip to content

Commit 0a637f6

Browse files
author
Sven Fuchs
committed
extend bump command to also take --tag and --release options, rename --to option to --version
1 parent 68a6d8f commit 0a637f6

File tree

3 files changed

+93
-25
lines changed

3 files changed

+93
-25
lines changed

lib/gem_release/version_file.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ def content
4848
end
4949

5050
def bumped_content
51-
content.sub(VERSION_PATTERN) { "#{$1}#{new_number}#{$3}"}
51+
content.sub(VERSION_PATTERN) { "#{$1}#{new_number}#{$3}" }
5252
end
5353
end
5454
end

lib/rubygems/commands/bump_command.rb

Lines changed: 23 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,31 @@
1-
require 'core_ext/string/camelize'
1+
require 'rubygems/commands/tag_command'
2+
require 'rubygems/commands/release_command'
23

34
class Gem::Commands::BumpCommand < Gem::Command
4-
include GemRelease
5+
include GemRelease, Gem::Commands
56
include Helpers, CommandOptions
67

78
attr_reader :arguments, :usage
89

9-
OPTIONS = { :to => :patch, :push => false }
10+
OPTIONS = { :version => 'patch', :push => false, :tag => false, :release => false }
1011

1112
def initialize
1213
super 'bump', 'Bump the gem version', OPTIONS
1314

14-
option :to, '-t', 'Target version: next [major|minor|patch] or a given version number [x.x.x]'
15-
option :push, '-p', 'Push to origin (defaults to false)'
15+
option :version, '-v', 'Target version: next [major|minor|patch] or a given version number [x.x.x]'
16+
option :push, '-p', 'Push to origin'
17+
option :tag, '-t', 'Create a git tag and push --tags to origin'
18+
option :release, '-r', 'Build gem from a gemspec and push to rubygems.org'
1619
end
1720

1821
def execute
1922
bump
2023
commit
21-
push if options[:push]
24+
push if options[:push] || options[:tag]
25+
release if options[:release]
26+
tag if options[:tag]
2227
end
23-
28+
2429
protected
2530

2631
def bump
@@ -38,8 +43,16 @@ def push
3843
say "Pushing to origin"
3944
`git push`
4045
end
41-
46+
47+
def release
48+
ReleaseCommand.new.invoke
49+
end
50+
51+
def tag
52+
TagCommand.new.invoke
53+
end
54+
4255
def version
43-
@version ||= VersionFile.new(:target => options[:to])
56+
@version ||= VersionFile.new(:target => options[:version])
4457
end
45-
end
58+
end

test/bump_command_test.rb

Lines changed: 69 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -5,63 +5,118 @@
55

66
class BumpCommandTest < Test::Unit::TestCase
77
include GemRelease
8-
8+
99
def setup
1010
build_sandbox
1111
stub_command(BootstrapCommand, :say)
12+
stub_command(TagCommand, :say)
1213
stub_command(BumpCommand, :say)
14+
stub_command(ReleaseCommand, :say)
1315
BootstrapCommand.new.send(:write_scaffold)
1416
end
15-
17+
1618
def teardown
1719
@version = nil
1820
teardown_sandbox
1921
end
20-
22+
2123
def version(options = {})
2224
@version ||= VersionFile.new(options)
2325
end
24-
26+
2527
test "gem bump" do
2628
command = BumpCommand.new
2729
command.expects(:`).with("git add #{version.send(:filename)}")
2830
command.expects(:`).with('git commit -m "Bump to 0.0.2"')
2931
command.invoke
3032
end
31-
33+
34+
test "gem bump --version 0.1.0" do
35+
command = BumpCommand.new
36+
command.expects(:`).with("git add #{version.send(:filename)}")
37+
command.expects(:`).with('git commit -m "Bump to 0.1.0"')
38+
command.invoke('--version', '0.1.0')
39+
end
40+
3241
test "gem bump --push" do
3342
command = BumpCommand.new
3443
command.expects(:`).with("git add #{version.send(:filename)}")
3544
command.expects(:`).with('git commit -m "Bump to 0.0.2"')
3645
command.expects(:`).with('git push')
3746
command.invoke('--push')
3847
end
39-
48+
49+
test "gem bump --push --tag" do
50+
command = BumpCommand.new
51+
command.expects(:`).with("git add #{version.send(:filename)}")
52+
command.expects(:`).with('git commit -m "Bump to 0.0.2"')
53+
command.expects(:`).with('git push')
54+
TagCommand.any_instance.stubs(:gem_version).returns('0.0.2')
55+
TagCommand.any_instance.expects(:`).with("git tag -am 'tag v0.0.2' v0.0.2")
56+
TagCommand.any_instance.expects(:`).with('git push --tags origin')
57+
command.invoke('--push', '--tag')
58+
end
59+
60+
test "gem bump --push --release" do
61+
command = BumpCommand.new
62+
command.expects(:`).with("git add #{version.send(:filename)}")
63+
command.expects(:`).with('git commit -m "Bump to 0.0.2"')
64+
command.expects(:`).with('git push')
65+
66+
release_command = ReleaseCommand.new
67+
ReleaseCommand.expects(:new).returns(release_command)
68+
ReleaseCommand.any_instance.expects(:build)
69+
ReleaseCommand.any_instance.expects(:push)
70+
ReleaseCommand.any_instance.expects(:remove)
71+
72+
command.invoke('--push', '--release')
73+
end
74+
75+
test "gem bump --push --tag --release" do
76+
command = BumpCommand.new
77+
command.expects(:`).with("git add #{version.send(:filename)}")
78+
command.expects(:`).with('git commit -m "Bump to 0.0.2"')
79+
command.expects(:`).with('git push')
80+
81+
release_command = ReleaseCommand.new
82+
ReleaseCommand.expects(:new).returns(release_command)
83+
ReleaseCommand.any_instance.expects(:build)
84+
ReleaseCommand.any_instance.expects(:push)
85+
ReleaseCommand.any_instance.expects(:remove)
86+
87+
release_command = TagCommand.new
88+
TagCommand.expects(:new).returns(release_command)
89+
TagCommand.any_instance.expects(:tag)
90+
TagCommand.any_instance.expects(:push)
91+
92+
command.invoke('--push', '--tag', '--release')
93+
end
94+
4095
test "old_number" do
4196
assert_equal '0.0.1', version.old_number
4297
end
43-
98+
4499
test "new_number w/ default target" do
45100
assert_equal '0.0.2', version.new_number
46101
end
47-
102+
48103
test "new_number w/ :patch target" do
49104
assert_equal '0.0.2', version(:target => :patch).new_number
50105
end
51-
106+
52107
test "new_number w/ :minor target" do
53108
assert_equal '0.1.0', version(:target => :minor).new_number
54109
end
55-
110+
56111
test "new_number w/ :major target" do
57112
assert_equal '1.0.0', version(:target => :major).new_number
58113
end
59-
114+
60115
test "new_number w/ given version number" do
61116
assert_equal '1.1.1', version(:target => '1.1.1').new_number
62117
end
63-
118+
64119
test "bumped_content" do
65-
assert_equal "module FooBar\n VERSION = \"0.0.2\"\nend", version.send(:bumped_content)
120+
assert_equal "module FooBar\n VERSION = \"0.0.2\"\nend\n", version.send(:bumped_content)
66121
end
67-
end
122+
end

0 commit comments

Comments
 (0)