Method: VimDo::CLI#merge

Defined in:
lib/vimdo/cli.rb

#merge(local, merge, remote, base = nil) ⇒ Object



113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
# File 'lib/vimdo/cli.rb', line 113

def merge(local, merge, remote, base = nil)

  [local, merge, remote].each do |f|
    unless File.readable?(f)
      raise PathError "#{f} is not readable!"
    end
  end
  raise PathError "#{base} is not readable!" unless File.readable?(base) or base.nil?

  local, merge, remote = [local, merge, remote].map {|f| File.expand_path(f) }

  merge_command =
  "tabnew<Bar>edit #{path(local)}" +
  "<Bar>diffsplit #{path(merge)}"  +
  "<Bar>diffsplit #{path(remote)}"

  if base
    base_split_command =
    "<Bar>diffsplit #{path(File.expand_path(base))}<Bar>wincmd J"
  else
    base_split_command = ''
  end

  switch_command = "<Bar>2wincmd w"

  commands(merge_command + base_split_command + switch_command)
  vim.foreground
end