mirror of
https://github.com/pre-commit/pre-commit.git
synced 2026-01-18 06:55:25 -06:00
Merge pull request #1415 from ModischFabrications/post_commit
Implement post-commit
This commit is contained in:
@@ -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(
|
||||
|
||||
@@ -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,)
|
||||
|
||||
@@ -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'
|
||||
|
||||
@@ -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'],
|
||||
|
||||
@@ -96,6 +96,7 @@ def test_run_legacy_recursive(tmpdir):
|
||||
('pre-merge-commit', []),
|
||||
('pre-push', ['branch_name', 'remote_name']),
|
||||
('commit-msg', ['.git/COMMIT_EDITMSG']),
|
||||
('post-commit', []),
|
||||
('post-checkout', ['old_head', 'new_head', '1']),
|
||||
# multiple choices for commit-editmsg
|
||||
('prepare-commit-msg', ['.git/COMMIT_EDITMSG']),
|
||||
@@ -149,6 +150,13 @@ def test_run_ns_commit_msg():
|
||||
assert ns.commit_msg_filename == '.git/COMMIT_MSG'
|
||||
|
||||
|
||||
def test_run_ns_post_commit():
|
||||
ns = hook_impl._run_ns('post-commit', True, (), b'')
|
||||
assert ns is not None
|
||||
assert ns.hook_stage == 'post-commit'
|
||||
assert ns.color is True
|
||||
|
||||
|
||||
def test_run_ns_post_checkout():
|
||||
ns = hook_impl._run_ns('post-checkout', True, ('a', 'b', 'c'), b'')
|
||||
assert ns is not None
|
||||
|
||||
@@ -726,6 +726,32 @@ def test_commit_msg_legacy(commit_msg_repo, tempdir_factory, store):
|
||||
assert second_line.startswith('Must have "Signed off by:"...')
|
||||
|
||||
|
||||
def test_post_commit_integration(tempdir_factory, store):
|
||||
path = git_dir(tempdir_factory)
|
||||
config = [
|
||||
{
|
||||
'repo': 'local',
|
||||
'hooks': [{
|
||||
'id': 'post-commit',
|
||||
'name': 'Post commit',
|
||||
'entry': 'touch post-commit.tmp',
|
||||
'language': 'system',
|
||||
'always_run': True,
|
||||
'verbose': True,
|
||||
'stages': ['post-commit'],
|
||||
}],
|
||||
},
|
||||
]
|
||||
write_config(path, config)
|
||||
with cwd(path):
|
||||
_get_commit_output(tempdir_factory)
|
||||
assert not os.path.exists('post-commit.tmp')
|
||||
|
||||
install(C.CONFIG_FILE, store, hook_types=['post-commit'])
|
||||
_get_commit_output(tempdir_factory)
|
||||
assert os.path.exists('post-commit.tmp')
|
||||
|
||||
|
||||
def test_post_checkout_integration(tempdir_factory, store):
|
||||
path = git_dir(tempdir_factory)
|
||||
config = [
|
||||
|
||||
@@ -880,7 +880,7 @@ def test_manifest_hooks(tempdir_factory, store):
|
||||
require_serial=False,
|
||||
stages=(
|
||||
'commit', 'merge-commit', 'prepare-commit-msg', 'commit-msg',
|
||||
'manual', 'post-checkout', 'push',
|
||||
'post-commit', 'manual', 'post-checkout', 'push',
|
||||
),
|
||||
types=['file'],
|
||||
verbose=False,
|
||||
|
||||
Reference in New Issue
Block a user