Class: GT::Commands::Modify

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

Class Method Summary collapse

Class Method Details

.run(argv) ⇒ Object

Raises:



6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
# File 'lib/gt/commands/modify.rb', line 6

def self.run(argv)
  msg_idx = argv.index("-m")
  message = msg_idx ? argv[msg_idx + 1] : nil
  raise GT::UserError, "Usage: gt modify [-m <message>] [-p]" if msg_idx && message.nil?

  patch = argv.include?("-p")
  branch = GT::Git.current_branch
  raise GT::UserError, "Cannot modify the main branch." if branch == GT::Git.main_branch

  # Interactive patch staging must happen before the spinner (SpinGroup masks stdin)
  if patch
    GT::Git.add_patch
  elsif !message
    # No message-only intent — stage everything (spinner will run below)
  end

  GT::UI.spinner("Modifying #{branch}") do
    GT::Git.add_all if !patch && !message
    GT::Git.amend(message: message)
    GT::Git.push(branch, force: true)
  end
  GT::Commands::Restack.run([])
end