mirror of
https://github.com/pre-commit/pre-commit.git
synced 2026-02-17 08:14:42 +04:00
Move test to install_uninstall test so environment variables apply
This commit is contained in:
parent
57cc814b8b
commit
0bb8a8fabe
6 changed files with 46 additions and 47 deletions
|
|
@ -15,6 +15,7 @@ from pre_commit.parse_shebang import find_executable
|
|||
from pre_commit.util import cmd_output
|
||||
from pre_commit.util import make_executable
|
||||
from pre_commit.util import resource_text
|
||||
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
|
||||
|
|
@ -512,9 +513,9 @@ def test_installed_from_venv(tempdir_factory, store):
|
|||
assert NORMAL_PRE_COMMIT_RUN.match(output)
|
||||
|
||||
|
||||
def _get_push_output(tempdir_factory, opts=()):
|
||||
def _get_push_output(tempdir_factory, remote='origin', opts=()):
|
||||
return cmd_output_mocked_pre_commit_home(
|
||||
'git', 'push', 'origin', 'HEAD:new_branch', *opts,
|
||||
'git', 'push', remote, 'HEAD:new_branch', *opts,
|
||||
tempdir_factory=tempdir_factory,
|
||||
retcode=None,
|
||||
)[:2]
|
||||
|
|
@ -589,6 +590,33 @@ def test_pre_push_new_upstream(tempdir_factory, store):
|
|||
assert 'Passed' in output
|
||||
|
||||
|
||||
def test_pre_push_environment_variables(tempdir_factory, store):
|
||||
config = {
|
||||
'repo': 'local',
|
||||
'hooks': [
|
||||
{
|
||||
'id': 'print-remote-info',
|
||||
'name': 'print remote info',
|
||||
'entry': 'bash -c "echo remote: $PRE_COMMIT_REMOTE_NAME"',
|
||||
'language': 'system',
|
||||
'verbose': True,
|
||||
},
|
||||
],
|
||||
}
|
||||
|
||||
upstream = git_dir(tempdir_factory)
|
||||
clone = tempdir_factory.get()
|
||||
cmd_output('git', 'clone', upstream, clone)
|
||||
add_config_to_repo(clone, config)
|
||||
with cwd(clone):
|
||||
install(C.CONFIG_FILE, store, hook_types=['pre-push'])
|
||||
|
||||
cmd_output('git', 'remote', 'rename', 'origin', 'origin2')
|
||||
retc, output = _get_push_output(tempdir_factory, remote='origin2')
|
||||
assert retc == 0
|
||||
assert '\nremote: origin2\n' in output
|
||||
|
||||
|
||||
def test_pre_push_integration_empty_push(tempdir_factory, store):
|
||||
upstream = make_consuming_repo(tempdir_factory, 'script_hooks_repo')
|
||||
path = tempdir_factory.get()
|
||||
|
|
|
|||
|
|
@ -456,8 +456,11 @@ def test_origin_source_error_msg_error(
|
|||
assert b'Specify both --origin and --source.' in printed
|
||||
|
||||
|
||||
def test_origin_source_both_ok(cap_out, store, repo_with_passing_hook):
|
||||
args = run_opts(origin='master', source='master')
|
||||
def test_all_push_options_ok(cap_out, store, repo_with_passing_hook):
|
||||
args = run_opts(
|
||||
origin='master', source='master',
|
||||
remote_name='origin', remote_url='https://example.com/repo',
|
||||
)
|
||||
ret, printed = _do_run(cap_out, store, repo_with_passing_hook, args)
|
||||
assert ret == 0
|
||||
assert b'Specify both --origin and --source.' not in printed
|
||||
|
|
@ -687,35 +690,6 @@ def test_stages(cap_out, store, repo_with_passing_hook):
|
|||
assert _run_for_stage('commit-msg').startswith(b'hook 5...')
|
||||
|
||||
|
||||
def test_push_remote_environment(cap_out, store, repo_with_passing_hook):
|
||||
config = {
|
||||
'repo': 'local',
|
||||
'hooks': [
|
||||
{
|
||||
'id': 'print-push-remote',
|
||||
'name': 'Print push remote name',
|
||||
'entry': 'entry: bash -c \'echo "$PRE_COMMIT_REMOTE_NAME"\'',
|
||||
'language': 'system',
|
||||
'verbose': bool(1),
|
||||
},
|
||||
],
|
||||
}
|
||||
add_config_to_repo(repo_with_passing_hook, config)
|
||||
|
||||
_test_run(
|
||||
cap_out,
|
||||
store,
|
||||
repo_with_passing_hook,
|
||||
opts={
|
||||
'push_remote_name': 'origin',
|
||||
'push_remote_url': 'https://github.com/pre-commit/pre-commit',
|
||||
},
|
||||
expected_outputs=[b'Print push remote name', b'Passed'],
|
||||
expected_ret=0,
|
||||
stage=['push'],
|
||||
)
|
||||
|
||||
|
||||
def test_commit_msg_hook(cap_out, store, commit_msg_repo):
|
||||
filename = '.git/COMMIT_EDITMSG'
|
||||
with open(filename, 'w') as f:
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue