Class: GT::Commands::Create

Inherits:
Object
  • Object
show all
Defined in:
lib/gt/commands/create.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
29
30
31
32
33
34
35
36
37
38
39
40
41
42
# File 'lib/gt/commands/create.rb', line 6

def self.run(argv)
  name = argv.shift
  raise GT::UserError, "Usage: gt create <name> [-m <message>] [-p]" if name.nil?

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

  patch = argv.include?("-p")
  parent = GT::Git.current_branch
  fork_point = GT::Git.rev_parse("HEAD")

  # All interactive staging must happen before the spinner (SpinGroup masks stdin)
  if patch
    GT::Git.add_patch
  else
    GT::Git.add_tracked
    GT::Git.untracked_files.each do |file|
      GT::Git.add_file(file) if GT::UI.confirm("Include untracked file '#{file}'?")
    end
  end

  GT::UI.spinner("Creating branch #{name}") do
    GT::Git.checkout(name, new_branch: true)
    GT::Git.commit(message)
    GT::Git.set_gt_parent(name, parent)
    GT::Git.set_gt_fork_point(name, fork_point)
    GT::Git.push(name)
  end

  GT::UI.info("Opening PR for {{bold:#{name}}} → {{bold:#{parent}}}")
  system("gh pr create --base #{parent} --head #{name} --fill")

  GT::UI.spinner("Updating stack comments") do
    GT::GitHub.update_stack_comments(GT::Stack.build_all)
  end
end