Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Merge pull request #8 from dgeb/bumpity-bump

Smoother bumps
  • Loading branch information...
commit d669adfce97c150b5f921978a68b07f259e52529 2 parents c971103 + 55fd3ef
@svenfuchs authored
View
2  Gemfile.lock
@@ -1,7 +1,7 @@
PATH
remote: .
specs:
- gem-release (0.0.17)
+ gem-release (0.0.19)
GEM
remote: http://rubygems.org/
View
20 README.md
@@ -53,13 +53,21 @@ Obviously ...
# (requires git config for github.user and github.token to be set)
$ gem bump # Bump the gem version to the next patch level (e.g. 0.0.1 to 0.0.2)
- $ gem bump --to minor # Bump the gem version to the next minor level (e.g. 0.0.1 to 0.1.0)
- $ gem bump --to major # Bump the gem version to the next major level (e.g. 0.0.1 to 1.0.0)
- $ gem bump --to 1.1.1 # Bump the gem version to the given version number
+ $ gem bump --version 1.1.1 # Bump the gem version to the given version number
+ $ gem bump --version major # Bump the gem version to the next major level (e.g. 0.0.1 to 1.0.0)
+ $ gem bump --version minor # Bump the gem version to the next minor level (e.g. 0.0.1 to 0.1.0)
+ $ gem bump --version patch # Bump the gem version to the next patch level (e.g. 0.0.1 to 0.0.2)
$ gem bump --push # Bump and git push to origin
-
-If the current directory (and subdirectories) contain multiple `*.gemspec` files then each of these gems will be bumped. I.e. gem-release
-will search for `lib/[gem_name]/version.rb` files and bump the version in each of them.
+ $ gem bump --tag # Bump and tag gem and pushes tags to the origin repository
+ $ gem bump --release # Bump and release gem
+ $ gem bump --tag --release # Bump, tag, push and release gem
+ $ gem bump --no-commit # Bump the gem version but don't git commit
+ # (will be ignored if combined with push, tag or release)
+
+If the current directory (and subdirectories) contain multiple `*.gemspec` files then each of these gems will be bumped
+to the same version. I.e. gem-release will search for `lib/[gem_name]/version.rb` files and bump the version in each of
+them. The version will either be the version specified with the --version option or the next patch level for the first
+version.rb file encountered.
## License
View
1  lib/gem_release/helpers.rb
@@ -60,7 +60,6 @@ def gemspec_filename
def in_gemspec_dirs
gemspec_dirs.each do |dir|
- @version = nil # UGH.
Dir.chdir(dir) { yield }
end
end
View
2  lib/gem_release/version.rb
@@ -1,5 +1,5 @@
module GemRelease
- VERSION = '0.0.19'
+ VERSION = '0.0.20'
class Version < Template
attr_reader :version
View
27 lib/rubygems/commands/bump_command.rb
@@ -29,21 +29,32 @@ def initialize(options = {})
end
def execute
+ @new_version_number = nil
+
+ # enforce option dependencies
+ options[:push] = options[:push] || options[:tag]
+ options[:commit] = options[:commit] || options[:push] || options[:release]
+
in_gemspec_dirs do
bump
end
- @version = nil # UGH
- commit if options[:commit]
- push if options[:push] || options[:tag]
- release if options[:release]
- tag if options[:tag]
+ if @new_version_number == nil
+ say "No version files could be found, so no actions were performed." unless quiet?
+ else
+ commit if options[:commit]
+ push if options[:push]
+ release if options[:release]
+ tag if options[:tag]
+ end
end
protected
def bump
+ version = VersionFile.new(:target => (@new_version_number || options[:version]))
if File.exist?(version.filename)
+ @new_version_number ||= version.new_number
say "Bumping #{gem_name} from #{version.old_number} to version #{version.new_number}" unless quiet?
version.bump!
`git add #{version.filename}` if options[:commit]
@@ -54,7 +65,7 @@ def bump
def commit
say "Creating commit" unless quiet?
- `git commit -m "Bump to #{version.new_number}"`
+ `git commit -m "Bump to #{@new_version_number}"`
end
def push
@@ -69,8 +80,4 @@ def release
def tag
TagCommand.new.invoke
end
-
- def version
- @version ||= VersionFile.new(:target => options[:version])
- end
end
View
34 test/bump_command_test.rb
@@ -7,7 +7,7 @@ class BumpCommandTest < Test::Unit::TestCase
include GemRelease
def setup
- build_sandbox(:spec_dirs => true)
+ build_sandbox(:gemspec_dirs => true)
stub_command(BootstrapCommand, :say)
stub_command(TagCommand, :say)
stub_command(BumpCommand, :say)
@@ -16,18 +16,18 @@ def setup
end
def teardown
- @version = nil
teardown_sandbox
end
def version(options = {})
- @version ||= VersionFile.new(options)
+ VersionFile.new(options)
end
test "gem bump" do
command = BumpCommand.new
- command.expects(:bump).times(spec_dirs.size)
- command.expects(:`).with("git add #{version.send(:filename)}")
+ in_gemspec_dirs do
+ command.expects(:`).with("git add #{version.send(:filename)}")
+ end
command.expects(:`).with('git commit -m "Bump to 0.0.2"')
command.invoke
end
@@ -47,14 +47,18 @@ def version(options = {})
test "gem bump --version 0.1.0" do
command = BumpCommand.new
- command.expects(:`).with("git add #{version.send(:filename)}")
+ in_gemspec_dirs do
+ command.expects(:`).with("git add #{version.send(:filename)}")
+ end
command.expects(:`).with('git commit -m "Bump to 0.1.0"')
command.invoke('--version', '0.1.0')
end
test "gem bump --push" do
command = BumpCommand.new
- command.expects(:`).with("git add #{version.send(:filename)}")
+ in_gemspec_dirs do
+ command.expects(:`).with("git add #{version.send(:filename)}")
+ end
command.expects(:`).with('git commit -m "Bump to 0.0.2"')
command.expects(:`).with('git push')
command.invoke('--push')
@@ -62,7 +66,9 @@ def version(options = {})
test "gem bump --push --tag" do
command = BumpCommand.new
- command.expects(:`).with("git add #{version.send(:filename)}")
+ in_gemspec_dirs do
+ command.expects(:`).with("git add #{version.send(:filename)}")
+ end
command.expects(:`).with('git commit -m "Bump to 0.0.2"')
command.expects(:`).with('git push')
TagCommand.any_instance.stubs(:gem_version).returns('0.0.2')
@@ -73,11 +79,13 @@ def version(options = {})
test "gem bump --push --release" do
command = BumpCommand.new
- command.expects(:`).with("git add #{version.send(:filename)}")
+ in_gemspec_dirs do
+ command.expects(:`).with("git add #{version.send(:filename)}")
+ end
command.expects(:`).with('git commit -m "Bump to 0.0.2"')
command.expects(:`).with('git push')
- count = spec_dirs.size
+ count = gemspec_dirs.size
ReleaseCommand.any_instance.expects(:build).times(count)
ReleaseCommand.any_instance.expects(:push).times(count)
ReleaseCommand.any_instance.expects(:remove).times(count)
@@ -87,11 +95,13 @@ def version(options = {})
test "gem bump --push --tag --release" do
command = BumpCommand.new
- command.expects(:`).with("git add #{version.send(:filename)}")
+ in_gemspec_dirs do
+ command.expects(:`).with("git add #{version.send(:filename)}")
+ end
command.expects(:`).with('git commit -m "Bump to 0.0.2"')
command.expects(:`).with('git push')
- count = spec_dirs.size
+ count = gemspec_dirs.size
ReleaseCommand.any_instance.expects(:build).times(count)
ReleaseCommand.any_instance.expects(:push).times(count)
ReleaseCommand.any_instance.expects(:remove).times(count)
View
2  test/gemspec_command_test.rb
@@ -5,7 +5,7 @@
class GemspecCommandTest < Test::Unit::TestCase
def setup
- build_sandbox
+ build_sandbox(:gemspec_dirs => true)
stub_command(GemspecCommand, :say)
stub_command(BootstrapCommand, :say)
end
View
2  test/gemspec_test.rb
@@ -7,7 +7,7 @@ class GemspecTest < Test::Unit::TestCase
include Gem::Commands
def setup
- build_sandbox
+ build_sandbox(:gemspec_dirs => true)
stub_exec(GemRelease::Gemspec,
'git config --get user.name' => 'John Doe',
'git config --get user.email' => 'john@example.org',
View
25 test/test_helper.rb
@@ -15,7 +15,7 @@
class Test::Unit::TestCase
include Gem::Commands
- attr_reader :base_dir, :spec_dirs
+ attr_reader :base_dir, :gemspec_dirs
def build_sandbox(options = {})
FileUtils.rm_r('tmp') if File.exists?('tmp')
@@ -24,13 +24,14 @@ def build_sandbox(options = {})
@base_dir = Pathname.new('tmp/foo-bar')
base_dir.mkpath
- spec_dirs.each do |dir|
- dir.mkpath
- Dir.chdir(dir) do
- BootstrapCommand.new(:scaffold => true, :quiet => true).execute
+ if options[:gemspec_dirs]
+ gemspec_dirs.each do |dir|
+ dir.mkpath
+ Dir.chdir(dir) do
+ BootstrapCommand.new(:scaffold => true, :quiet => true).execute
+ end
end
end
-
Dir.chdir(base_dir)
end
@@ -39,8 +40,16 @@ def teardown_sandbox
FileUtils.rm_r('tmp')
end
- def spec_dirs
- @spec_dirs ||= %w(. spec_1 spec_2 nested/spec_3).map { |dir| base_dir.join(dir) }
+ def gemspec_dirs
+ @gemspec_dirs ||= %w(. spec_1 spec_2 nested/spec_3).map { |dir| base_dir.join(dir) }
+ end
+
+ def in_gemspec_dirs
+ Dir.chdir(@cwd) do
+ gemspec_dirs.each do |dir|
+ Dir.chdir(dir) { yield }
+ end
+ end
end
def stub_exec(klass, commands)
Please sign in to comment.
Something went wrong with that request. Please try again.