Class: Rlt::Commands::Close

Inherits:
Object
  • Object
show all
Defined in:
lib/rlt/commands/close.rb

Class Method Summary collapse

Class Method Details

.any_conflict?Boolean

Returns:

  • (Boolean)


47
48
49
50
51
# File 'lib/rlt/commands/close.rb', line 47

def self.any_conflict?
  result = Utils::GitUtil.any_conflict?
  print_conflict_error if result
  result
end

.default_branch(config) ⇒ Object



36
37
38
# File 'lib/rlt/commands/close.rb', line 36

def self.default_branch(config)
  config['default_branch'] || 'master'
end

.default_branch_now?(default_branch) ⇒ Boolean

Returns:

  • (Boolean)


30
31
32
33
34
# File 'lib/rlt/commands/close.rb', line 30

def self.default_branch_now?(default_branch)
  result = Utils::GitUtil.current_branch_name == default_branch
  print_default_branch_now_error(default_branch) if result
  result
end

.delete_branch(current_branch_name) ⇒ Object



67
68
69
70
71
72
# File 'lib/rlt/commands/close.rb', line 67

def self.delete_branch(current_branch_name)
  Utils::GitUtil.delete_branch(current_branch_name, print_info: true)
  Utils::GitUtil.remotes.each do |remote|
    Utils::GitUtil.safely_delete_remote_branch(remote, current_branch_name, print_info: true)
  end
end

.merge_back_and_forth(current_branch_name, default_branch) ⇒ Object



40
41
42
43
44
45
# File 'lib/rlt/commands/close.rb', line 40

def self.merge_back_and_forth(current_branch_name, default_branch)
  Utils::GitUtil.merge_from(default_branch, print_info: true)
  return if any_conflict?
  Utils::GitUtil.checkout(default_branch, print_info: true)
  Utils::GitUtil.merge_from(current_branch_name, print_info: true)
end


62
63
64
65
# File 'lib/rlt/commands/close.rb', line 62

def self.print_conflict_error
  Utils::Logger.error 'Aborting the process due to the conflict.'
  Utils::Logger.error 'Resolve them first, and try it again.'
end


58
59
60
# File 'lib/rlt/commands/close.rb', line 58

def self.print_default_branch_now_error(default_branch)
  Utils::Logger.error "You cannot close `#{default_branch}`."
end


53
54
55
56
# File 'lib/rlt/commands/close.rb', line 53

def self.print_uncommitted_changes_error
  Utils::Logger.error 'There are uncommitted changes.'
  Utils::Logger.error 'Commit them first!'
end

.run(config) ⇒ Object



6
7
8
9
10
11
12
# File 'lib/rlt/commands/close.rb', line 6

def self.run(config)
  default_branch = default_branch(config)
  current_branch_name = Utils::GitUtil.current_branch_name
  return if should_stop?(default_branch)
  run_internal(current_branch_name, default_branch)
  Utils::Logger.info "Done closing `#{current_branch_name}`."
end

.run_internal(current_branch_name, default_branch) ⇒ Object



14
15
16
17
# File 'lib/rlt/commands/close.rb', line 14

def self.run_internal(current_branch_name, default_branch)
  merge_back_and_forth(current_branch_name, default_branch)
  delete_branch(current_branch_name)
end

.should_stop?(default_branch) ⇒ Boolean

Returns:

  • (Boolean)


19
20
21
22
# File 'lib/rlt/commands/close.rb', line 19

def self.should_stop?(default_branch)
  return true if uncommitted_changes?
  return true if default_branch_now?(default_branch)
end

.uncommitted_changes?Boolean

Returns:

  • (Boolean)


24
25
26
27
28
# File 'lib/rlt/commands/close.rb', line 24

def self.uncommitted_changes?
  result = Utils::GitUtil.uncommitted_change?
  print_uncommitted_changes_error if result
  result
end