Class: RGitFlow::Tasks::Hotfix::Start

Inherits:
Task
  • Object
show all
Defined in:
lib/rgitflow/tasks/hotfix/start.rb

Constant Summary

Constants included from Printing

Printing::DEBUG_PREFIX, Printing::ERROR_PREFIX, Printing::INPUT_PREFIX, Printing::STATUS_PREFIX

Instance Attribute Summary

Attributes inherited from Task

#after, #before, #dependencies, #description, #name, #namespaces

Instance Method Summary collapse

Methods inherited from Task

#define

Methods included from Console

#execute, #invoke, #multi_task, #task?

Methods included from Printing

#debug, #error, #prompt, #status

Constructor Details

#initialize(git) ⇒ Start

Returns a new instance of Start.



7
8
9
# File 'lib/rgitflow/tasks/hotfix/start.rb', line 7

def initialize(git)
  super(git, 'start', 'Start a hotfix branch', ['rgitflow', 'hotfix'])
end

Instance Method Details

#runObject (protected)



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
43
44
45
# File 'lib/rgitflow/tasks/hotfix/start.rb', line 13

def run
  status 'Starting hotfix branch...'

  unless @git.current_branch == RGitFlow::Config.options[:master]
    error 'Cannot start a hotfix branch unless you are in the master branch'
    abort
  end

  branch = ENV['BRANCH']

  while branch.blank?
    error 'Cannot create a branch with an empty name!'
    prompt 'Please enter a name for your hotfix branch:'
    branch = STDIN.gets.chomp
  end

  branch = [RGitFlow::Config.options[:hotfix], branch].join('/')

  if @git.is_local_branch? branch
    error 'Cannot create a branch that already exists locally'
    abort
  end

  if @git.is_remote_branch? branch
    error 'Cannot create a branch that already exists remotely'
    abort
  end

  @git.branch(branch).create
  @git.branch(branch).checkout

  status "Started hotfix branch #{branch}!"
end