git - Invalid syntax in python script for pre commit hook -
this question has answer here:
- syntax error on print python 3 [duplicate] 10 answers
i using following python code hook pre commit hook jshint when execute git commit -m "commit comment"
shows error
file ".git/hooks/pre-commit", line 29 print error ^ syntaxerror: invalid syntax
here code
#!/usr/bin/env python import os, sys """ checks git commit jshint. checks staged files """ def jshint(): errors = [] # staged files f = os.popen('git diff --cached --name-only --diff-filter=acm') file in f.read().splitlines(): # makes sure we're dealing javascript files if file.endswith('.js') , not file.startswith('node_modules/'): g = os.popen('jshint ' + file) # add errors files error in g.readlines(): errors.append(error) # got errors? if errors: i, error in enumerate(errors): print error, #### <----- line 29 # abort commit sys.exit(1) # sys.exit(0) if __name__ == '__main__': jshint()
i don't know python , cannot find correct syntax.
if python installation indeed python 3 (which probable these days) change line to:
print(error, end=" ")
for backwards compatibility can add following imports:
from __future__ import print_function
Comments
Post a Comment