|
15 | 15 | from pre_commit.util import cmd_output |
16 | 16 | from pre_commit.util import make_executable |
17 | 17 | from pre_commit.util import resource_text |
| 18 | +from testing.fixtures import add_config_to_repo |
18 | 19 | from testing.fixtures import git_dir |
19 | 20 | from testing.fixtures import make_consuming_repo |
20 | 21 | from testing.fixtures import remove_config_from_repo |
@@ -512,9 +513,9 @@ def test_installed_from_venv(tempdir_factory, store): |
512 | 513 | assert NORMAL_PRE_COMMIT_RUN.match(output) |
513 | 514 |
|
514 | 515 |
|
515 | | -def _get_push_output(tempdir_factory, opts=()): |
| 516 | +def _get_push_output(tempdir_factory, remote='origin', opts=()): |
516 | 517 | return cmd_output_mocked_pre_commit_home( |
517 | | - 'git', 'push', 'origin', 'HEAD:new_branch', *opts, |
| 518 | + 'git', 'push', remote, 'HEAD:new_branch', *opts, |
518 | 519 | tempdir_factory=tempdir_factory, |
519 | 520 | retcode=None, |
520 | 521 | )[:2] |
@@ -589,6 +590,33 @@ def test_pre_push_new_upstream(tempdir_factory, store): |
589 | 590 | assert 'Passed' in output |
590 | 591 |
|
591 | 592 |
|
| 593 | +def test_pre_push_environment_variables(tempdir_factory, store): |
| 594 | + config = { |
| 595 | + 'repo': 'local', |
| 596 | + 'hooks': [ |
| 597 | + { |
| 598 | + 'id': 'print-remote-info', |
| 599 | + 'name': 'print remote info', |
| 600 | + 'entry': 'bash -c "echo remote: $PRE_COMMIT_REMOTE_NAME"', |
| 601 | + 'language': 'system', |
| 602 | + 'verbose': True, |
| 603 | + }, |
| 604 | + ], |
| 605 | + } |
| 606 | + |
| 607 | + upstream = git_dir(tempdir_factory) |
| 608 | + clone = tempdir_factory.get() |
| 609 | + cmd_output('git', 'clone', upstream, clone) |
| 610 | + add_config_to_repo(clone, config) |
| 611 | + with cwd(clone): |
| 612 | + install(C.CONFIG_FILE, store, hook_types=['pre-push']) |
| 613 | + |
| 614 | + cmd_output('git', 'remote', 'rename', 'origin', 'origin2') |
| 615 | + retc, output = _get_push_output(tempdir_factory, remote='origin2') |
| 616 | + assert retc == 0 |
| 617 | + assert '\nremote: origin2\n' in output |
| 618 | + |
| 619 | + |
592 | 620 | def test_pre_push_integration_empty_push(tempdir_factory, store): |
593 | 621 | upstream = make_consuming_repo(tempdir_factory, 'script_hooks_repo') |
594 | 622 | path = tempdir_factory.get() |
|
0 commit comments