Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion pre_commit/commands/hook_impl.py
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,7 @@ def _pre_push_ns(
_EXPECTED_ARG_LENGTH_BY_HOOK = {
'commit-msg': 1,
'post-checkout': 3,
Comment thread
ModischFabrications marked this conversation as resolved.
'post-commit': 0,
'pre-commit': 0,
'pre-merge-commit': 0,
'pre-push': 2,
Expand Down Expand Up @@ -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(
Expand Down
3 changes: 2 additions & 1 deletion pre_commit/commands/run.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,)
Expand Down
4 changes: 2 additions & 2 deletions pre_commit/constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@

# `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'
2 changes: 1 addition & 1 deletion pre_commit/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -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'],
Expand Down
8 changes: 8 additions & 0 deletions tests/commands/hook_impl_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,7 @@ def call(*_, **__):
('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']),
Expand Down Expand Up @@ -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
Expand Down
26 changes: 26 additions & 0 deletions tests/commands/install_uninstall_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Comment thread
ModischFabrications marked this conversation as resolved.
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 = [
Expand Down
2 changes: 1 addition & 1 deletion tests/repository_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down