lib/gem/release/cmds/bump.rb in gem-release-2.0.0.dev.5 vs lib/gem/release/cmds/bump.rb in gem-release-2.0.0.rc.1
- old
+ new
@@ -41,10 +41,11 @@
arg :gem_name, 'name of the gem (optional, will use the directory name, or all gemspecs if --recurse is given)'
DESCR = {
version: 'Target version: next [major|minor|patch|pre|release] or a given version number [x.x.x]',
+ branch: 'Check out a new branch for the target version (e.g. `v1.0.0`)',
commit: 'Create a commit after incrementing gem version',
message: 'Commit message template',
skip_ci: 'Add the [skip ci] tag to the commit message',
push: 'Push the new commit to the git remote repository',
remote: 'Git remote to push to (defaults to origin)',
@@ -57,14 +58,16 @@
DEFAULTS = {
commit: true,
message: 'Bump %{name} to %{version} %{skip_ci}',
push: false,
+ branch: false,
remote: 'origin',
skip_ci: false,
sign: false,
- recurse: false
+ recurse: false,
+ pretend: false
}
opt '-v', '--version VERSION', descr(:version) do |value|
opts[:version] = value
end
@@ -91,10 +94,14 @@
opt '-s', '--sign', descr(:sign) do |value|
opts[:sign] = value
end
+ opt '--branch [BRANCH]', descr(:branch) do |value|
+ opts[:branch] = value.nil? ? true : value
+ end
+
opt '-t', '--tag', descr(:tag) do |value|
opts[:tag] = value
end
opt '-r', '--release', descr(:release) do |value|
@@ -111,26 +118,29 @@
MSGS = {
bump: 'Bumping %s from version %s to %s',
version: 'Changing version in %s from %s to %s',
git_add: 'Staging %s',
+ git_checkout: 'Checking out branch %s',
git_commit: 'Creating commit',
git_push: 'Pushing to the %s git repository',
git_dirty: 'Uncommitted changes found. Please commit or stash.',
not_found: 'Ignoring %s. Version file %s not found.',
no_git_remote: 'Cannot push to missing git remote %s.'
}
CMDS = {
- git_add: 'git add %s',
- git_commit: 'git commit -m %p %s',
- git_push: 'git push %s'
+ git_checkout: 'git checkout -b %s',
+ git_add: 'git add %s',
+ git_commit: 'git commit -m %p %s',
+ git_push: 'git push %s'
}
def run
in_gem_dirs do
validate
+ checkout if opts[:branch]
bump
commit if opts[:commit]
push if opts[:commit] && opts[:push]
reset
end
@@ -139,15 +149,19 @@
end
private
def validate
- abort :git_dirty unless git_clean?
- abort :no_git_remote, remote if push? && !git_remotes.include?(remote.to_s)
+ abort :git_dirty unless git.clean?
+ abort :no_git_remote, remote if push? && !git.remotes.include?(remote.to_s)
abort :not_found, gem.name, version.path || '?' unless version.exists?
end
+ def checkout
+ cmd :git_checkout, branch
+ end
+
def bump
announce :bump, gem.name, version.from, version.to
return true if pretend?
notice :version, version.path, version.from, version.to
version.bump
@@ -166,9 +180,18 @@
Tag.new(context, args, opts).run
end
def release
Release.new(context, args, except(opts, :tag)).run
+ end
+
+ def branch
+ case opts[:branch]
+ when ::String
+ opts[:branch]
+ when true
+ "v#{version.to}"
+ end
end
def message
args = { name: gem.name, skip_ci: opts[:skip_ci] ? '[skip ci]' : '' }
args = args.merge(version.to_h)