Skip to content

Instantly share code, notes, and snippets.

@kgn
Created June 30, 2011 02:45
Show Gist options
  • Star 3 You must be signed in to star a gist
  • Fork 2 You must be signed in to fork a gist
  • Save kgn/1055516 to your computer and use it in GitHub Desktop.
Save kgn/1055516 to your computer and use it in GitHub Desktop.
import sys
import os
import subprocess
def git(args, **kwargs):
environ = os.environ.copy()
if 'repo' in kwargs:
environ['GIT_DIR'] = kwargs['repo']
if 'work' in kwargs:
environ['GIT_WORK_TREE'] = kwargs['work']
proc = subprocess.Popen(args, stdout=subprocess.PIPE, env=environ)
return proc.communicate()
def get_changed_files(base, commit, **kw):
(results, code) = git(('git', 'diff', '--numstat', '--name-only', "%s..%s" % (base, commit)), **kw)
return results.strip().split('\n')
def get_new_file(filename, commit):
(results, code) = git(('git', 'show', '%s:%s' % (commit, filename)))
return results
repo = os.getcwd()
basedir = os.path.join(repo, "..")
line = sys.stdin.read()
(base, commit, ref) = line.strip().split()
modified = get_changed_files(base, commit)
for fname in modified:
print "=====", fname
print get_new_file(fname, commit)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment