Class: Gitx::Cli::NukeCommand

Inherits:
BaseCommand show all
Defined in:
lib/gitx/cli/nuke_command.rb

Instance Method Summary collapse

Methods included from Thor::Actions

#ask_editor

Instance Method Details

#nuke(bad_branch) ⇒ Object



11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
# File 'lib/gitx/cli/nuke_command.rb', line 11

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.empty?

  last_known_good_tag = current_build_tag(good_branch)
  return unless yes?("Reset #{bad_branch} to #{last_known_good_tag}? (y/n)", :green)

  assert_aggregate_branch!(bad_branch)
  return if migrations_need_to_be_reverted?(bad_branch, last_known_good_tag)

  say 'Resetting '
  say "#{bad_branch} ", :green
  say 'branch to '
  say last_known_good_tag, :green

  checkout_branch config.base_branch
  run_git_cmd('branch', '--delete', '--force', bad_branch) rescue Gitx::Executor::ExecutionError
  run_git_cmd('push', 'origin', '--delete', bad_branch) rescue Gitx::Executor::ExecutionError
  run_git_cmd 'checkout', '-b', bad_branch, last_known_good_tag
  run_git_cmd 'share'
  checkout_branch config.base_branch
end