@@ -55,12 +55,25 @@ def _add_config_option(parser):
5555 )
5656
5757
58+ class AppendReplaceDefault (argparse .Action ):
59+ def __init__ (self , * args , ** kwargs ):
60+ super (AppendReplaceDefault , self ).__init__ (* args , ** kwargs )
61+ self .appended = False
62+
63+ def __call__ (self , parser , namespace , values , option_string = None ):
64+ if not self .appended :
65+ setattr (namespace , self .dest , [])
66+ self .appended = True
67+ getattr (namespace , self .dest ).append (values )
68+
69+
5870def _add_hook_type_option (parser ):
5971 parser .add_argument (
6072 '-t' , '--hook-type' , choices = (
6173 'pre-commit' , 'pre-push' , 'prepare-commit-msg' , 'commit-msg' ,
6274 ),
63- action = 'append' ,
75+ action = AppendReplaceDefault ,
76+ default = ['pre-commit' ],
6477 dest = 'hook_types' ,
6578 )
6679
@@ -121,11 +134,6 @@ def _adjust_args_and_chdir(args):
121134 args .files = [os .path .relpath (filename ) for filename in args .files ]
122135 if args .command == 'try-repo' and os .path .exists (args .repo ):
123136 args .repo = os .path .relpath (args .repo )
124- if (
125- args .command in {'install' , 'uninstall' , 'init-templatedir' } and
126- not args .hook_types
127- ):
128- args .hook_types = ['pre-commit' ]
129137
130138
131139def main (argv = None ):
0 commit comments