public
Description: The Git TextMate Bundle
Homepage: http://tim.theenchanter.com/
Clone URL: git://github.com/timcharper/git-tmbundle.git
git-tmbundle / Commands / Git Resolve Conflicts.tmCommand
100644 74 lines (60 sloc) 1.94 kb
1
2
3
4
5
6
7
8
9
10
11
12
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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
  <key>beforeRunningCommand</key>
  <string>nop</string>
  <key>command</key>
  <string>#!/usr/bin/env ruby
 
# Resolve conflicts command for git/FileMerge
# By Tim Harper
# http://code.leadmediapartners.com/
 
require "fileutils"
FM="/Developer/Applications/Utilities/FileMerge.app/Contents/MacOS/FileMerge"
require ENV['TM_BUNDLE_SUPPORT'] + '/environment.rb'
require ENV['TM_SUPPORT_PATH'] + '/lib/escape.rb'
 
state = :both
 
input_file_path = ENV['TM_FILEPATH']
input_filename = File.basename(input_file_path)
 
input = $&lt;.read
 
left = ""
right = ""
 
 
input.each { |line|
  if /^(&lt;{7}|={7}|&gt;{7})($| )/.match(line)
    state =
      case $1
      when "&lt;&lt;&lt;&lt;&lt;&lt;&lt;" then :left
      when "=======" then :right
      when "&gt;&gt;&gt;&gt;&gt;&gt;&gt;" then :both
      end
    next
  end
  left &lt;&lt; line if state == :left || state == :both
  right &lt;&lt; line if state == :right || state == :both
}
 
if left==right
  puts "No conflicts to resolve in #{input_file_path}."
  exit
end
 
filename = "git-conflict-resolve"
tmp_path = "/tmp/git-conflict-resolve/"
 
FileUtils.rm_rf(tmp_path)
FileUtils.mkdir_p(tmp_path)
 
left_file = "#{tmp_path}left-#{input_filename}.rb"
right_file = "#{tmp_path}right-#{input_filename}.rb"
File.open(left_file, "w") { |f| f.puts left }
File.open(right_file, "w") { |f| f.puts right }
 
%x{#{FM} -left #{e_sh left_file} -right #{e_sh right_file} -merge #{e_sh input_file_path} &amp;&gt;/dev/null &amp; }
</string>
  <key>input</key>
  <string>document</string>
  <key>keyEquivalent</key>
  <string>^G</string>
  <key>name</key>
  <string>Edit Conflicts With FileMerge…</string>
  <key>output</key>
  <string>showAsTooltip</string>
  <key>uuid</key>
  <string>7CE2C842-EBC4-443C-8DDB-3B16AC593D9A</string>
</dict>
</plist>