Class: GT::Commands::Checkout

Inherits:
Object
  • Object
show all
Defined in:
lib/gt/commands/checkout.rb

Class Method Summary collapse

Class Method Details

.run(argv) ⇒ Object

Raises:



6
7
8
9
10
11
12
13
14
15
# File 'lib/gt/commands/checkout.rb', line 6

def self.run(argv)
  branches = GT::Stack.build_all
  raise GT::UserError, "No stack found. Use `gt create` to start a stack." if branches.length < 2

  current = GT::Git.current_branch
  target = argv.first || GT::UI.prompt_select("Switch to branch:", branches)
  raise GT::UserError, "Branch '#{target}' is not in the stack." unless branches.include?(target)

  GT::Git.checkout(target) unless target == current
end