Skip to content

Instantly share code, notes, and snippets.

@christophmeissner
Last active February 8, 2018 09:46
Show Gist options
  • Save christophmeissner/4eeae0dac0de2be3dfe31d6f7f941a71 to your computer and use it in GitHub Desktop.
Save christophmeissner/4eeae0dac0de2be3dfe31d6f7f941a71 to your computer and use it in GitHub Desktop.
#!/usr/bin/env python
import os
import subprocess
import sys
PATH = os.environ["PATH"]
if '/usr/local/bin' not in PATH:
PATH = "/usr/local/bin:{}".format(PATH)
env = {"PATH": PATH}
print >> sys.stdout, "Running pre-commit hook for `git clang-format`..."
sys.stdout.flush()
output = subprocess.check_output(["git-clang-format", "--diff"], env=env)
success_messages = (
'no modified files to format',
'clang-format did not modify any files')
if output and not any(map(lambda m: m in output, success_messages)):
print >> sys.stderr, "clang-format found the files with peding formatting:"
for line in output.split("\n"):
if line.startswith("+++"):
print >> sys.stderr, " ", line.split("/")[-1]
exit(1)
exit(0)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment