When doing git merges I end up with automatically generated git difference 
files that have changes marked with <<<<<<< ======= >>>>>>>.  These can be a 
pain to work through and what I really want is to back them out into BBEdit's 
compare files tool so I can see the changes. I wrote this quick script to do 
that.

It assumes the front document is one of these files marked up by git's 
difference tool. It creates two new text windows with how the original files 
would have looked and then compares those files. I can then use the comparison 
tool in BBEdit to merge the two files and copy that result back into the 
original file and complete the merge using the command line.

You can run the script in Script Editor or store it in BBEdit's scripts folder 
to run it.

[fletcher]


tell application "BBEdit"
  activate
  -- Get contents of GIT diff file
  set diff_temp to contents of front window
  -- Create first temporary file
  set diff_one to make new document
  set contents of diff_one to diff_temp
  replace 
"<<<<<<<[^\\r]*\\r([\\s\\S]*?)\\r=======[^\\r]*\\r([\\s\\S]*?)\\r>>>>>>>[^\\r]*"
 using "\\1" searching in diff_one options {search mode:grep, starting at 
top:true, returning results:false, showing results:false}
  -- Create second temporary file
  set diff_two to make new document
  set contents of diff_two to diff_temp
  replace 
"<<<<<<<[^\\r]*\\r([\\s\\S]*?)\\r=======[^\\r]*\\r([\\s\\S]*?)\\r>>>>>>>[^\\r]*"
 using "\\2" searching in diff_two options {search mode:grep, starting at 
top:true, returning results:false, showing results:false}
  -- Perform comparison
  compare text document 1 against text document 2
end tell

-- 
This is the BBEdit Talk public discussion group. If you have a 
feature request or would like to report a problem, please email
"[email protected]" rather than posting to the group.
Follow @bbedit on Twitter: <http://www.twitter.com/bbedit>

--- 
You received this message because you are subscribed to the Google Groups 
"BBEdit Talk" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].

Reply via email to