1717PASS_FAIL_LENGTH = 6
1818
1919
20- def _run_single_hook (runner , repository , hook_id , all_files = False ):
20+ def _run_single_hook (runner , repository , hook_id , all_files = False , verbose = False ):
2121 if all_files :
2222 get_filenames = git .get_all_files_matching
2323 else :
@@ -38,29 +38,28 @@ def _run_single_hook(runner, repository, hook_id, all_files=False):
3838 get_filenames (hook ['files' ], hook ['exclude' ]),
3939 )
4040
41+ output = '\n ' .join ([stdout , stderr ]).strip ()
4142 if retcode != repository .hooks [hook_id ]['expected_return_value' ]:
42- output = '\n ' .join ([stdout , stderr ]).strip ()
4343 retcode = 1
4444 color = RED
4545 pass_fail = 'Failed'
4646 else :
47- output = ''
4847 retcode = 0
4948 color = GREEN
5049 pass_fail = 'Passed'
5150
5251
5352 print '{0}{1}{2}' .format (color , pass_fail , NORMAL )
5453
55- if output :
54+ if output and ( retcode or verbose ) :
5655 print
5756 print output
5857 print
5958
6059 return retcode
6160
6261
63- def run_hooks (runner , all_files = False ):
62+ def run_hooks (runner , all_files = False , verbose = False ):
6463 """Actually run the hooks."""
6564 retval = 0
6665
@@ -71,19 +70,21 @@ def run_hooks(runner, all_files=False):
7170 repo ,
7271 hook_id ,
7372 all_files = all_files ,
73+ verbose = verbose ,
7474 )
7575
7676 return retval
7777
7878
79- def run_single_hook (runner , hook_id , all_files = False ):
79+ def run_single_hook (runner , hook_id , all_files = False , verbose = False ):
8080 for repo in runner .repositories :
8181 if hook_id in repo .hooks :
8282 return _run_single_hook (
8383 runner ,
8484 repo ,
8585 hook_id ,
8686 all_files = all_files ,
87+ verbose = verbose ,
8788 )
8889 else :
8990 print 'No hook with id {0}' .format (hook_id )
@@ -110,6 +111,7 @@ def run(argv):
110111 '--all-files' , '-a' , action = 'store_true' , default = False ,
111112 help = 'Run on all the files in the repo.' ,
112113 )
114+ run .add_argument ('--verbose' , '-v' , action = 'store_true' , default = False )
113115
114116 help = subparsers .add_parser ('help' , help = 'Show help for a specific command.' )
115117 help .add_argument ('help_cmd' , nargs = '?' , help = 'Command to show help for.' )
@@ -131,9 +133,16 @@ def run(argv):
131133 return commands .autoupdate (runner )
132134 elif args .command == 'run' :
133135 if args .hook :
134- return run_single_hook (runner , args .hook , all_files = args .all_files )
136+ return run_single_hook (
137+ runner ,
138+ args .hook ,
139+ all_files = args .all_files ,
140+ verbose = args .verbose ,
141+ )
135142 else :
136- return run_hooks (runner , all_files = args .all_files )
143+ return run_hooks (
144+ runner , all_files = args .all_files , verbose = args .verbose ,
145+ )
137146 elif args .command == 'help' :
138147 if args .help_cmd :
139148 parser .parse_args ([args .help_cmd , '--help' ])
0 commit comments