#NEWLINE# def _setup_pre_commit_hook( self ) : #NEWLINE# #INDENT# '\n        Copy the pre-commit hook found at config.pre_commit_hook to the\n        closest .git directory.  If no .git directory exists, throw an\n        exception.\n        ' #NEWLINE# if ( self . config . get ( 'pre_commit_hook' ) is None ) : #NEWLINE# #INDENT# return #NEWLINE# #UNINDENT# check_dir = os . getcwd ( ) #NEWLINE# while 1 : #NEWLINE# #INDENT# if os . path . exists ( os . path . join ( check_dir , '.git' ) ) : #NEWLINE# #INDENT# break #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# if ( os . path . normpath ( check_dir ) == '/' ) : #NEWLINE# #INDENT# raise Exception ( 'No .git directory found for pre-commit hook' ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# check_dir = os . path . join ( check_dir , os . pardir ) #NEWLINE# #UNINDENT# #UNINDENT# #UNINDENT# hook_path = os . path . join ( os . getcwd ( ) , self . config [ 'pre_commit_hook' ] ) #NEWLINE# source = os . path . join ( hook_path ) #NEWLINE# dest = os . path . join ( check_dir , '.git' , 'hooks' , 'pre-commit' ) #NEWLINE# sys . stdout . write ( ( 'Setup git pre-commit hook: \n\t%s\n\t-> %s\n' % ( dest , source ) ) ) #NEWLINE# try : #NEWLINE# #INDENT# if ( os . readlink ( dest ) == source ) : #NEWLINE# #INDENT# return #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# os . unlink ( dest ) #NEWLINE# #UNINDENT# #UNINDENT# except OSError : #NEWLINE# #INDENT# pass #NEWLINE# #UNINDENT# os . symlink ( source , dest )