Skip to content

Instantly share code, notes, and snippets.

@troelskn
Forked from kgn/pre-receive.py
Created October 30, 2011 11:12
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 troelskn/1325799 to your computer and use it in GitHub Desktop.
Save troelskn/1325799 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)
@hasegeli
Copy link

I developed an extensive script to validate commits, if anyone find it helpful:

https://github.com/innogames/igcommit

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment