mirror of
https://github.com/pre-commit/pre-commit.git
synced 2026-02-17 08:14:42 +04:00
Adds support for prepare-commit-msg hooks
Adds a prepare-commit-msg hook stage which allows for hooks which add dynamic suggested/placeholder text to commit messages that an author can use as a starting point for writing a commit message
This commit is contained in:
parent
809b7482df
commit
e60f541559
7 changed files with 142 additions and 6 deletions
|
|
@ -190,7 +190,7 @@ def _compute_cols(hooks, verbose):
|
|||
def _all_filenames(args):
|
||||
if args.origin and args.source:
|
||||
return git.get_changed_files(args.origin, args.source)
|
||||
elif args.hook_stage == 'commit-msg':
|
||||
elif args.hook_stage in ['prepare-commit-msg', 'commit-msg']:
|
||||
return (args.commit_msg_filename,)
|
||||
elif args.files:
|
||||
return args.files
|
||||
|
|
|
|||
|
|
@ -21,6 +21,6 @@ LOCAL_REPO_VERSION = '1'
|
|||
VERSION = importlib_metadata.version('pre_commit')
|
||||
|
||||
# `manual` is not invoked by any installed git hook. See #719
|
||||
STAGES = ('commit', 'commit-msg', 'manual', 'push')
|
||||
STAGES = ('commit', 'prepare-commit-msg', 'commit-msg', 'manual', 'push')
|
||||
|
||||
DEFAULT = 'default'
|
||||
|
|
|
|||
|
|
@ -52,7 +52,9 @@ def _add_config_option(parser):
|
|||
|
||||
def _add_hook_type_option(parser):
|
||||
parser.add_argument(
|
||||
'-t', '--hook-type', choices=('pre-commit', 'pre-push', 'commit-msg'),
|
||||
'-t', '--hook-type', choices=(
|
||||
'pre-commit', 'pre-push', 'prepare-commit-msg', 'commit-msg',
|
||||
),
|
||||
default='pre-commit',
|
||||
)
|
||||
|
||||
|
|
|
|||
|
|
@ -161,6 +161,7 @@ def _pre_push(stdin):
|
|||
|
||||
def _opts(stdin):
|
||||
fns = {
|
||||
'prepare-commit-msg': lambda _: ('--commit-msg-filename', sys.argv[1]),
|
||||
'commit-msg': lambda _: ('--commit-msg-filename', sys.argv[1]),
|
||||
'pre-commit': lambda _: (),
|
||||
'pre-push': _pre_push,
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue