Class: FlashFlow::Resolve

Inherits:
Object
  • Object
show all
Defined in:
lib/flash_flow/resolve.rb

Defined Under Namespace

Classes: NothingToResolve

Instance Method Summary collapse

Constructor Details

#initialize(git_config, branch_info_file, opts = {}) ⇒ Resolve

Returns a new instance of Resolve.



11
12
13
14
15
16
# File 'lib/flash_flow/resolve.rb', line 11

def initialize(git_config, branch_info_file, opts={})
  @logger = opts[:logger]
  @branch_info_file = branch_info_file
  @cmd_runner = CmdRunner.new(logger: @logger)
  @git = ShadowGit.new(git_config, @logger)
end

Instance Method Details

#bash_messageObject



62
63
64
# File 'lib/flash_flow/resolve.rb', line 62

def bash_message
  puts "\nNote: You are in a special flash_flow directory (#{Dir.pwd}). The files still open in your editor will not reflect the merge conflicts, open them from this shell to get the conflicted versions.\n\nPlease fix the following conflicts and then 'exit':\n#{unresolved_conflicts.join("\n")}\n\n"
end

#git_resetObject



54
55
56
# File 'lib/flash_flow/resolve.rb', line 54

def git_reset
  @git.run("reset --hard HEAD")
end

#launch_bashObject



66
67
68
69
70
71
72
# File 'lib/flash_flow/resolve.rb', line 66

def launch_bash
  bash_message

  with_init_file do |file|
    system("bash --init-file #{file} -i")
  end
end

#manual_instructionsObject



18
19
20
21
# File 'lib/flash_flow/resolve.rb', line 18

def manual_instructions
  check_for_conflict
  puts manual_not_merged_instructions
end

#manual_not_merged_instructionsObject



85
86
87
88
89
90
91
92
93
94
95
96
97
98
# File 'lib/flash_flow/resolve.rb', line 85

def manual_not_merged_instructions
  <<-EOS

Run the following commands to fix the merge conflict and then re-run flash_flow:
  pushd #{flash_flow_directory}
  git checkout #{branch.conflict_sha}
  git merge #{working_branch}
  # Resolve the conflicts
  git add <conflicted files>
  git commit --no-edit
  popd

  EOS
end

#merge_conflictedObject



49
50
51
52
# File 'lib/flash_flow/resolve.rb', line 49

def merge_conflicted
  @git.run("checkout #{branch.conflict_sha}")
  @git.run("merge #{@git.remote}/#{working_branch}")
end

#rerereObject



58
59
60
# File 'lib/flash_flow/resolve.rb', line 58

def rerere
  @git.run("rerere")
end

#startObject



23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
# File 'lib/flash_flow/resolve.rb', line 23

def start
  check_for_conflict

  in_working_branch do
    merge_conflicted

    if unresolved_conflicts.empty?
      puts "You have already resolved all conflicts."
    else
      launch_bash

      rerere

      unless unresolved_conflicts.empty?
        puts "There are still unresolved conflicts in these files:\n#{unresolved_conflicts.join("\n")}\n\n"
      end
    end

    git_reset
  end
end

#unresolved_conflictsObject



45
46
47
# File 'lib/flash_flow/resolve.rb', line 45

def unresolved_conflicts
  @git.unresolved_conflicts
end

#with_init_file {|filename| ... } ⇒ Object

Yields:

  • (filename)


74
75
76
77
78
79
80
81
82
83
# File 'lib/flash_flow/resolve.rb', line 74

def with_init_file
  filename = '.flash_flow_init'
  File.open(filename, 'w') do |f|
    f.puts(init_file_contents)
  end

  yield filename

  File.delete(filename)
end