mirror of
https://github.com/pre-commit/pre-commit.git
synced 2026-02-17 08:14:42 +04:00
Add: post-merge hook support
This commit is contained in:
parent
d7b189ce56
commit
6b73138c73
9 changed files with 82 additions and 5 deletions
|
|
@ -76,6 +76,7 @@ def _ns(
|
|||
remote_url: Optional[str] = None,
|
||||
commit_msg_filename: Optional[str] = None,
|
||||
checkout_type: Optional[str] = None,
|
||||
is_squash_merge: Optional[str] = None,
|
||||
) -> argparse.Namespace:
|
||||
return argparse.Namespace(
|
||||
color=color,
|
||||
|
|
@ -88,6 +89,7 @@ def _ns(
|
|||
commit_msg_filename=commit_msg_filename,
|
||||
all_files=all_files,
|
||||
checkout_type=checkout_type,
|
||||
is_squash_merge=is_squash_merge,
|
||||
files=(),
|
||||
hook=None,
|
||||
verbose=False,
|
||||
|
|
@ -158,6 +160,7 @@ _EXPECTED_ARG_LENGTH_BY_HOOK = {
|
|||
'post-commit': 0,
|
||||
'pre-commit': 0,
|
||||
'pre-merge-commit': 0,
|
||||
'post-merge': 1,
|
||||
'pre-push': 2,
|
||||
}
|
||||
|
||||
|
|
@ -199,6 +202,8 @@ def _run_ns(
|
|||
hook_type, color,
|
||||
from_ref=args[0], to_ref=args[1], checkout_type=args[2],
|
||||
)
|
||||
elif hook_type == 'post-merge':
|
||||
return _ns(hook_type, color, is_squash_merge=args[0])
|
||||
else:
|
||||
raise AssertionError(f'unexpected hook type: {hook_type}')
|
||||
|
||||
|
|
|
|||
|
|
@ -245,7 +245,7 @@ def _compute_cols(hooks: Sequence[Hook]) -> int:
|
|||
|
||||
def _all_filenames(args: argparse.Namespace) -> Collection[str]:
|
||||
# these hooks do not operate on files
|
||||
if args.hook_stage in {'post-checkout', 'post-commit'}:
|
||||
if args.hook_stage in {'post-checkout', 'post-commit', 'post-merge'}:
|
||||
return ()
|
||||
elif args.hook_stage in {'prepare-commit-msg', 'commit-msg'}:
|
||||
return (args.commit_msg_filename,)
|
||||
|
|
@ -379,6 +379,9 @@ def run(
|
|||
if args.checkout_type:
|
||||
environ['PRE_COMMIT_CHECKOUT_TYPE'] = args.checkout_type
|
||||
|
||||
if args.is_squash_merge:
|
||||
environ['PRE_COMMIT_IS_SQUASH_MERGE'] = args.is_squash_merge
|
||||
|
||||
# Set pre_commit flag
|
||||
environ['PRE_COMMIT'] = '1'
|
||||
|
||||
|
|
|
|||
|
|
@ -18,7 +18,7 @@ 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',
|
||||
'post-commit', 'manual', 'post-checkout', 'push',
|
||||
'post-commit', 'manual', 'post-checkout', 'push', 'post-merge',
|
||||
)
|
||||
|
||||
DEFAULT = 'default'
|
||||
|
|
|
|||
|
|
@ -67,8 +67,8 @@ class AppendReplaceDefault(argparse.Action):
|
|||
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-commit', 'post-checkout',
|
||||
'pre-commit', 'pre-merge-commit', 'pre-push', 'prepare-commit-msg',
|
||||
'commit-msg', 'post-commit', 'post-checkout', 'post-merge',
|
||||
),
|
||||
action=AppendReplaceDefault,
|
||||
default=['pre-commit'],
|
||||
|
|
@ -136,6 +136,13 @@ def _add_run_options(parser: argparse.ArgumentParser) -> None:
|
|||
'file from the index, flag=0).'
|
||||
),
|
||||
)
|
||||
parser.add_argument(
|
||||
'--is-squash-merge',
|
||||
help=(
|
||||
'During a post-merge hook, indicates whether the merge was a '
|
||||
'squash merge'
|
||||
),
|
||||
)
|
||||
|
||||
|
||||
def _adjust_args_and_chdir(args: argparse.Namespace) -> None:
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue