Class: Octopolo::Scripts::NewBranch

Inherits:
Object
  • Object
show all
Includes:
CLIWrapper, ConfigWrapper, GitWrapper
Defined in:
lib/octopolo/scripts/new_branch.rb

Instance Attribute Summary collapse

Attributes included from CLIWrapper

#cli

Attributes included from GitWrapper

#git

Attributes included from ConfigWrapper

#config

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(new_branch_name = nil, source_branch_name = nil) ⇒ NewBranch

Returns a new instance of NewBranch.



18
19
20
21
# File 'lib/octopolo/scripts/new_branch.rb', line 18

def initialize(new_branch_name=nil, source_branch_name=nil)
  @new_branch_name    = new_branch_name
  @source_branch_name = source_branch_name || config.deploy_branch
end

Instance Attribute Details

#new_branch_nameObject

Returns the value of attribute new_branch_name.



11
12
13
# File 'lib/octopolo/scripts/new_branch.rb', line 11

def new_branch_name
  @new_branch_name
end

#source_branch_nameObject

Returns the value of attribute source_branch_name.



12
13
14
# File 'lib/octopolo/scripts/new_branch.rb', line 12

def source_branch_name
  @source_branch_name
end

Class Method Details

.execute(new_branch_name = nil, source_branch_name = nil) ⇒ Object



14
15
16
# File 'lib/octopolo/scripts/new_branch.rb', line 14

def self.execute(new_branch_name=nil, source_branch_name=nil)
  new(new_branch_name, source_branch_name).execute
end

Instance Method Details

#default_source_branch_nameObject

Public: Provide a default value if none is given



36
37
38
# File 'lib/octopolo/scripts/new_branch.rb', line 36

def default_source_branch_name
  config.deploy_branch
end

#executeObject

Public: Perform the script

Raises:

  • (ArgumentError)


24
25
26
27
28
29
30
31
32
33
# File 'lib/octopolo/scripts/new_branch.rb', line 24

def execute
  raise ArgumentError unless new_branch_name
  if !git.reserved_branch?(new_branch_name) || cli.ask_boolean(Git::RESERVED_BRANCH_CONFIRM_MESSAGE)
    git.new_branch(new_branch_name, source_branch_name)
  else
    message = Git::RESERVED_BRANCH_MESSAGE
    git.alert_reserved_branch message
    exit 1
  end
end