Skip to content

Instantly share code, notes, and snippets.

Created April 7, 2016 16:29
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save anonymous/ce82f214ba78db50a288f12238d05897 to your computer and use it in GitHub Desktop.
Save anonymous/ce82f214ba78db50a288f12238d05897 to your computer and use it in GitHub Desktop.
Arcanist wrapper
#!/usr/bin/python2.7
from __future__ import print_function
import os
import stat
import subprocess
import sys
REAL_ARC='/usr/local/google/home/jlebar/code/arcanist/bin/arc'
def main():
if len(sys.argv) != 3 or sys.argv[1] != 'diff':
# Not "arc diff blah"; fall through.
return
try:
# TODO: This loses us color and pagination, but oh well.
diff = subprocess.check_output(['git', 'clang-format', '--diff', sys.argv[2]])
except subprocess.CalledProcessError:
yorn = raw_input('Error running git-clang-format. Continue running arc? [yN] ')
if yorn.lower() == 'y':
return
sys.exit(1)
if not diff:
return
print('clang-format suggested the following changes:\n')
print(diff)
mode = os.fstat(sys.stdin.fileno()).st_mode
if stat.S_ISFIFO(mode) or stat.S_ISREG(mode):
print('Detected non-interactive mode. Proceeding to arc diff...',
file=sys.stderr)
return
yorn = raw_input('Proceed with arc diff? [yN] ')
if yorn.lower() != 'y':
sys.exit(1)
if __name__ == '__main__':
main()
os.execv(REAL_ARC, sys.argv)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment