Skip to content

Instantly share code, notes, and snippets.

@hugowetterberg
Created February 17, 2010 19:56
Show Gist options
  • Save hugowetterberg/306959 to your computer and use it in GitHub Desktop.
Save hugowetterberg/306959 to your computer and use it in GitHub Desktop.
Script that shows the diff for a file (using git) using Apple's graphical diff tool FileMerge
#!/usr/bin/env python
import os
import sys
import tempfile
import subprocess
file = sys.argv[1];
proc = subprocess.Popen(['git', 'ls-tree', 'HEAD'],
stdout=subprocess.PIPE, stderr = subprocess.PIPE)
output, errors = proc.communicate()
for line in output.split("\n"):
if len(line) > 0:
props, name = line.split('\t')
props = props.split(' ')
if name == file:
blob = props[2]
if blob:
proc = subprocess.Popen(['git', 'show', blob],
stdout=subprocess.PIPE, stderr = subprocess.PIPE)
output, errors = proc.communicate()
original = tempfile.NamedTemporaryFile('w')
original.write(output)
original.flush()
subprocess.call(['opendiff', original.name, file])
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment