mirror of
https://github.com/pre-commit/pre-commit.git
synced 2026-02-17 08:14:42 +04:00
Merge pull request #1339 from andrewhare/andrewhare/post-checkout
Add post-checkout
This commit is contained in:
commit
566f1afcd4
9 changed files with 77 additions and 5 deletions
|
|
@ -104,6 +104,16 @@ def test_run_ns_commit_msg():
|
|||
assert ns.commit_msg_filename == '.git/COMMIT_MSG'
|
||||
|
||||
|
||||
def test_run_ns_post_checkout():
|
||||
ns = hook_impl._run_ns('post-checkout', True, ('a', 'b', 'c'), b'')
|
||||
assert ns is not None
|
||||
assert ns.hook_stage == 'post-checkout'
|
||||
assert ns.color is True
|
||||
assert ns.source == 'a'
|
||||
assert ns.origin == 'b'
|
||||
assert ns.checkout_type == 'c'
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def push_example(tempdir_factory):
|
||||
src = git_dir(tempdir_factory)
|
||||
|
|
|
|||
|
|
@ -20,6 +20,7 @@ from testing.fixtures import add_config_to_repo
|
|||
from testing.fixtures import git_dir
|
||||
from testing.fixtures import make_consuming_repo
|
||||
from testing.fixtures import remove_config_from_repo
|
||||
from testing.fixtures import write_config
|
||||
from testing.util import cmd_output_mocked_pre_commit_home
|
||||
from testing.util import cwd
|
||||
from testing.util import git_commit
|
||||
|
|
@ -725,6 +726,31 @@ def test_commit_msg_legacy(commit_msg_repo, tempdir_factory, store):
|
|||
assert second_line.startswith('Must have "Signed off by:"...')
|
||||
|
||||
|
||||
def test_post_checkout_integration(tempdir_factory, store):
|
||||
path = git_dir(tempdir_factory)
|
||||
config = {
|
||||
'repo': 'local',
|
||||
'hooks': [{
|
||||
'id': 'post-checkout',
|
||||
'name': 'Post checkout',
|
||||
'entry': 'bash -c "echo ${PRE_COMMIT_ORIGIN}"',
|
||||
'language': 'system',
|
||||
'always_run': True,
|
||||
'verbose': True,
|
||||
'stages': ['post-checkout'],
|
||||
}],
|
||||
}
|
||||
write_config(path, config)
|
||||
with cwd(path):
|
||||
cmd_output('git', 'add', '.')
|
||||
git_commit()
|
||||
install(C.CONFIG_FILE, store, hook_types=['post-checkout'])
|
||||
retc, _, stderr = cmd_output('git', 'checkout', '-b', 'feature')
|
||||
assert retc == 0
|
||||
_, head, _ = cmd_output('git', 'rev-parse', 'HEAD')
|
||||
assert head in str(stderr)
|
||||
|
||||
|
||||
def test_prepare_commit_msg_integration_failing(
|
||||
failing_prepare_commit_msg_repo, tempdir_factory, store,
|
||||
):
|
||||
|
|
|
|||
|
|
@ -18,6 +18,7 @@ from pre_commit.commands.run import Classifier
|
|||
from pre_commit.commands.run import filter_by_include_exclude
|
||||
from pre_commit.commands.run import run
|
||||
from pre_commit.util import cmd_output
|
||||
from pre_commit.util import EnvironT
|
||||
from pre_commit.util import make_executable
|
||||
from testing.auto_namedtuple import auto_namedtuple
|
||||
from testing.fixtures import add_config_to_repo
|
||||
|
|
@ -466,6 +467,15 @@ def test_all_push_options_ok(cap_out, store, repo_with_passing_hook):
|
|||
assert b'Specify both --origin and --source.' not in printed
|
||||
|
||||
|
||||
def test_checkout_type(cap_out, store, repo_with_passing_hook):
|
||||
args = run_opts(origin='', source='', checkout_type='1')
|
||||
environ: EnvironT = {}
|
||||
ret, printed = _do_run(
|
||||
cap_out, store, repo_with_passing_hook, args, environ,
|
||||
)
|
||||
assert environ['PRE_COMMIT_CHECKOUT_TYPE'] == '1'
|
||||
|
||||
|
||||
def test_has_unmerged_paths(in_merge_conflict):
|
||||
assert _has_unmerged_paths() is True
|
||||
cmd_output('git', 'add', '.')
|
||||
|
|
|
|||
|
|
@ -871,7 +871,7 @@ def test_manifest_hooks(tempdir_factory, store):
|
|||
require_serial=False,
|
||||
stages=(
|
||||
'commit', 'merge-commit', 'prepare-commit-msg', 'commit-msg',
|
||||
'manual', 'push',
|
||||
'manual', 'post-checkout', 'push',
|
||||
),
|
||||
types=['file'],
|
||||
verbose=False,
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue