lib/gitx/cli/nuke_command.rb in gitx-2.13.2 vs lib/gitx/cli/nuke_command.rb in gitx-2.13.3
- old
+ new
@@ -4,11 +4,11 @@
module Gitx
module Cli
class NukeCommand < BaseCommand
desc 'nuke', 'nuke the specified aggregate branch and reset it to a known good state'
- method_option :destination, :type => :string, :aliases => '-d', :desc => 'destination branch to reset to'
+ method_option :destination, type: :string, aliases: '-d', desc: 'destination branch to reset to'
def nuke(bad_branch)
good_branch = options[:destination] || ask("What branch do you want to reset #{bad_branch} to? (default: #{bad_branch})")
good_branch = bad_branch if good_branch.length == 0
last_known_good_tag = current_build_tag(good_branch)
@@ -20,12 +20,12 @@
say "#{bad_branch} ", :green
say 'branch to '
say last_known_good_tag, :green
checkout_branch Gitx::BASE_BRANCH
- run_cmd "git branch -D #{bad_branch}", :allow_failure => true
- run_cmd "git push origin --delete #{bad_branch}", :allow_failure => true
+ run_cmd "git branch -D #{bad_branch}", allow_failure: true
+ run_cmd "git push origin --delete #{bad_branch}", allow_failure: true
run_cmd "git checkout -b #{bad_branch} #{last_known_good_tag}"
run_cmd "git push origin #{bad_branch}"
run_cmd "git branch --set-upstream-to origin/#{bad_branch}"
checkout_branch Gitx::BASE_BRANCH
end
@@ -37,19 +37,19 @@
outdated_migrations = run_cmd("git diff #{last_known_good_tag}...#{bad_branch} --name-only db/migrate").split
return false if outdated_migrations.empty?
say "#{bad_branch} contains migrations that may need to be reverted. Ensure any reversable migrations are reverted on affected databases before nuking.", :red
say 'Example commands to revert outdated migrations:'
- outdated_migrations.reverse.each do |migration|
+ outdated_migrations.reverse_each do |migration|
version = File.basename(migration).split('_').first
say "rake db:migrate:down VERSION=#{version}"
end
!yes?("Are you sure you want to nuke #{bad_branch}? (y/n) ", :green)
end
def current_build_tag(branch)
last_build_tag = build_tags_for_branch(branch).last
- raise "No known good tag found for branch: #{branch}. Verify tag exists via `git tag -l 'build-#{branch}-*'`" unless last_build_tag
+ fail "No known good tag found for branch: #{branch}. Verify tag exists via `git tag -l 'build-#{branch}-*'`" unless last_build_tag
last_build_tag
end
def build_tags_for_branch(branch)
run_cmd 'git fetch --tags'