1#!/usr/bin/python 2 3# 4# Copyright 2016, The Android Open Source Project 5# 6# Licensed under the Apache License, Version 2.0 (the "License"); 7# you may not use this file except in compliance with the License. 8# You may obtain a copy of the License at 9# 10# http://www.apache.org/licenses/LICENSE-2.0 11# 12# Unless required by applicable law or agreed to in writing, software 13# distributed under the License is distributed on an "AS IS" BASIS, 14# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15# See the License for the specific language governing permissions and 16# limitations under the License. 17# 18 19"""Pre-push hook to run Checkstyle on changes that are about to be uploaded. 20 21 Usage: add a symbolic link from /path/to/git/repo/.git/hooks/pre-push to 22 this file. 23""" 24 25import sys 26import checkstyle 27 28 29def main(): 30 print '\nStarting Checkstyle!\n' 31 sys.stdout.flush() 32 33 ins = raw_input() 34 (errors, warnings) = checkstyle.RunCheckstyleOnACommit(ins.split(' ')[1]) 35 36 if errors or warnings: 37 print 'Upload anyway (y/N)?:' 38 sys.stdin = open('/dev/tty') 39 sys.stdout.flush() 40 answer = raw_input() 41 if 'y' == answer.lower(): 42 sys.exit(0) 43 else: 44 sys.exit(1) 45 46 47if __name__ == '__main__': 48 main() 49