mirror of
https://github.com/pre-commit/pre-commit.git
synced 2026-01-14 21:10:27 -06:00
Add post-checkout
This commit is contained in:
committed by
Anthony Sottile
parent
1c641b1c28
commit
18fa004254
@@ -74,6 +74,7 @@ def _ns(
|
||||
remote_name: Optional[str] = None,
|
||||
remote_url: Optional[str] = None,
|
||||
commit_msg_filename: Optional[str] = None,
|
||||
checkout_type: Optional[str] = None,
|
||||
) -> argparse.Namespace:
|
||||
return argparse.Namespace(
|
||||
color=color,
|
||||
@@ -84,6 +85,7 @@ def _ns(
|
||||
remote_url=remote_url,
|
||||
commit_msg_filename=commit_msg_filename,
|
||||
all_files=all_files,
|
||||
checkout_type=checkout_type,
|
||||
files=(),
|
||||
hook=None,
|
||||
verbose=False,
|
||||
@@ -157,6 +159,11 @@ def _run_ns(
|
||||
return _ns(hook_type, color, commit_msg_filename=args[0])
|
||||
elif hook_type in {'pre-merge-commit', 'pre-commit'}:
|
||||
return _ns(hook_type, color)
|
||||
elif hook_type == 'post-checkout':
|
||||
return _ns(
|
||||
hook_type, color, source=args[0], origin=args[1],
|
||||
checkout_type=args[2],
|
||||
)
|
||||
else:
|
||||
raise AssertionError(f'unexpected hook type: {hook_type}')
|
||||
|
||||
|
||||
@@ -316,6 +316,9 @@ def run(
|
||||
environ['PRE_COMMIT_REMOTE_NAME'] = args.remote_name
|
||||
environ['PRE_COMMIT_REMOTE_URL'] = args.remote_url
|
||||
|
||||
if args.checkout_type:
|
||||
environ['PRE_COMMIT_CHECKOUT_TYPE'] = args.checkout_type
|
||||
|
||||
with contextlib.ExitStack() as exit_stack:
|
||||
if stash:
|
||||
exit_stack.enter_context(staged_files_only(store.directory))
|
||||
|
||||
@@ -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', 'manual',
|
||||
'push',
|
||||
'post-checkout', 'push',
|
||||
)
|
||||
|
||||
DEFAULT = 'default'
|
||||
|
||||
@@ -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',
|
||||
'prepare-commit-msg', 'commit-msg', 'post-checkout',
|
||||
),
|
||||
action=AppendReplaceDefault,
|
||||
default=['pre-commit'],
|
||||
@@ -92,11 +92,17 @@ def _add_run_options(parser: argparse.ArgumentParser) -> None:
|
||||
parser.add_argument('--verbose', '-v', action='store_true', default=False)
|
||||
parser.add_argument(
|
||||
'--origin', '-o',
|
||||
help="The origin branch's commit_id when using `git push`.",
|
||||
help=(
|
||||
"The origin branch's commit_id when using `git push`. "
|
||||
'The ref of the previous HEAD when using `git checkout`.'
|
||||
),
|
||||
)
|
||||
parser.add_argument(
|
||||
'--source', '-s',
|
||||
help="The remote branch's commit_id when using `git push`.",
|
||||
help=(
|
||||
"The remote branch's commit_id when using `git push`. "
|
||||
'The ref of the new HEAD when using `git checkout`.'
|
||||
),
|
||||
)
|
||||
parser.add_argument(
|
||||
'--commit-msg-filename',
|
||||
@@ -123,6 +129,14 @@ def _add_run_options(parser: argparse.ArgumentParser) -> None:
|
||||
'--files', nargs='*', default=[],
|
||||
help='Specific filenames to run hooks on.',
|
||||
)
|
||||
parser.add_argument(
|
||||
'--checkout-type',
|
||||
help=(
|
||||
'Indicates whether the checkout was a branch checkout '
|
||||
'(changing branches, flag=1) or a file checkout (retrieving a '
|
||||
'file from the index, flag=0).'
|
||||
),
|
||||
)
|
||||
|
||||
|
||||
def _adjust_args_and_chdir(args: argparse.Namespace) -> None:
|
||||
|
||||
Reference in New Issue
Block a user