There's no exit function in your code. How about replace exit
to sys.exit
?
#!/usr/bin/env python
import subprocess
import sys
if len(sys.argv) == 8:
# assume this was passed to git; we can of course do
# some parsing to check if we got valid git style args
args = [sys.argv[2], sys.argv[5]]
elif len(sys.argv) == 3:
args = sys.argv[1:]
else:
print "Not a valid number of args (2 or 7) to this diff program"
sys.exit(1)
print "Files: ", args
for filename in args:
filetype = subprocess.check_output(['file', filename])
if filetype.find('text') == -1:
args.insert(0, 'diff')
print "A binary file was found: " + filename + ", deferring to diff"
#sys.stdout.flush()
subprocess.call(args)
sys.exit(0)
EDIT: git
depend on external diff's exit status. diff
exit with 0 only if there is no differce. So changed the code not to use diff's exit status.
PS: Without sys.stdout.flush(), diff
output come before print
output.