add support for post-commit

This commit is contained in:
ModischFabrications 2020-04-25 01:21:12 +02:00 committed by Anthony Sottile
parent 3b3b33ea29
commit 26adf1d560
7 changed files with 42 additions and 6 deletions

View file

@ -150,6 +150,7 @@ def _pre_push_ns(
_EXPECTED_ARG_LENGTH_BY_HOOK = {
'commit-msg': 1,
'post-checkout': 3,
'post-commit': 0,
'pre-commit': 0,
'pre-merge-commit': 0,
'pre-push': 2,
@ -186,7 +187,7 @@ def _run_ns(
return _pre_push_ns(color, args, stdin)
elif hook_type in {'commit-msg', 'prepare-commit-msg'}:
return _ns(hook_type, color, commit_msg_filename=args[0])
elif hook_type in {'pre-merge-commit', 'pre-commit'}:
elif hook_type in {'post-commit', 'pre-merge-commit', 'pre-commit'}:
return _ns(hook_type, color)
elif hook_type == 'post-checkout':
return _ns(

View file

@ -221,7 +221,8 @@ def _compute_cols(hooks: Sequence[Hook]) -> int:
def _all_filenames(args: argparse.Namespace) -> Collection[str]:
if args.hook_stage == 'post-checkout': # no files for post-checkout
# these hooks do not operate on files
if args.hook_stage in {'post-checkout', 'post-commit'}:
return ()
elif args.hook_stage in {'prepare-commit-msg', 'commit-msg'}:
return (args.commit_msg_filename,)

View file

@ -17,8 +17,8 @@ VERSION = importlib_metadata.version('pre_commit')
# `manual` is not invoked by any installed git hook. See #719
STAGES = (
'commit', 'merge-commit', 'prepare-commit-msg', 'commit-msg', 'manual',
'post-checkout', 'push',
'commit', 'merge-commit', 'prepare-commit-msg', 'commit-msg',
'post-commit', 'manual', 'post-checkout', 'push',
)
DEFAULT = 'default'

View file

@ -79,7 +79,7 @@ def _add_hook_type_option(parser: argparse.ArgumentParser) -> None:
parser.add_argument(
'-t', '--hook-type', choices=(
'pre-commit', 'pre-merge-commit', 'pre-push',
'prepare-commit-msg', 'commit-msg', 'post-checkout',
'prepare-commit-msg', 'commit-msg', 'post-commit', 'post-checkout',
),
action=AppendReplaceDefault,
default=['pre-commit'],