mirror of
https://github.com/pre-commit/pre-commit.git
synced 2026-02-19 09:04:41 +04:00
fix hooks firing during staged_files_only
This commit is contained in:
parent
0670e0b287
commit
928938a6a1
5 changed files with 53 additions and 5 deletions
|
|
@ -789,6 +789,37 @@ def test_post_checkout_integration(tempdir_factory, store):
|
|||
assert 'some_file' not in stderr
|
||||
|
||||
|
||||
def test_skips_post_checkout_unstaged_changes(tempdir_factory, store):
|
||||
path = git_dir(tempdir_factory)
|
||||
config = {
|
||||
'repo': 'local',
|
||||
'hooks': [{
|
||||
'id': 'fail',
|
||||
'name': 'fail',
|
||||
'entry': 'fail',
|
||||
'language': 'fail',
|
||||
'always_run': True,
|
||||
'stages': ['post-checkout'],
|
||||
}],
|
||||
}
|
||||
write_config(path, config)
|
||||
with cwd(path):
|
||||
cmd_output('git', 'add', '.')
|
||||
_get_commit_output(tempdir_factory)
|
||||
|
||||
install(C.CONFIG_FILE, store, hook_types=['pre-commit'])
|
||||
install(C.CONFIG_FILE, store, hook_types=['post-checkout'])
|
||||
|
||||
# make an unstaged change so staged_files_only fires
|
||||
open('file', 'a').close()
|
||||
cmd_output('git', 'add', 'file')
|
||||
with open('file', 'w') as f:
|
||||
f.write('unstaged changes')
|
||||
|
||||
retc, out = _get_commit_output(tempdir_factory, all_files=False)
|
||||
assert retc == 0
|
||||
|
||||
|
||||
def test_prepare_commit_msg_integration_failing(
|
||||
failing_prepare_commit_msg_repo, tempdir_factory, store,
|
||||
):
|
||||
|
|
|
|||
|
|
@ -1022,3 +1022,9 @@ def test_args_hook_only(cap_out, store, repo_with_passing_hook):
|
|||
run_opts(hook='do_not_commit'),
|
||||
)
|
||||
assert b'identity-copy' not in printed
|
||||
|
||||
|
||||
def test_skipped_without_any_setup_for_post_checkout(in_git_dir, store):
|
||||
environ = {'_PRE_COMMIT_SKIP_POST_CHECKOUT': '1'}
|
||||
opts = run_opts(hook_stage='post-checkout')
|
||||
assert run(C.CONFIG_FILE, store, opts, environ=environ) == 0
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue