|
4 | 4 | from unittest import mock |
5 | 5 |
|
6 | 6 | import pre_commit.constants as C |
| 7 | +from pre_commit import git |
7 | 8 | from pre_commit.commands import install_uninstall |
8 | 9 | from pre_commit.commands.install_uninstall import CURRENT_HASH |
9 | 10 | from pre_commit.commands.install_uninstall import install |
@@ -728,27 +729,39 @@ def test_commit_msg_legacy(commit_msg_repo, tempdir_factory, store): |
728 | 729 |
|
729 | 730 | def test_post_checkout_integration(tempdir_factory, store): |
730 | 731 | path = git_dir(tempdir_factory) |
731 | | - config = { |
732 | | - 'repo': 'local', |
733 | | - 'hooks': [{ |
734 | | - 'id': 'post-checkout', |
735 | | - 'name': 'Post checkout', |
736 | | - 'entry': 'bash -c "echo ${PRE_COMMIT_ORIGIN}"', |
737 | | - 'language': 'system', |
738 | | - 'always_run': True, |
739 | | - 'verbose': True, |
740 | | - 'stages': ['post-checkout'], |
741 | | - }], |
742 | | - } |
| 732 | + config = [ |
| 733 | + { |
| 734 | + 'repo': 'local', |
| 735 | + 'hooks': [{ |
| 736 | + 'id': 'post-checkout', |
| 737 | + 'name': 'Post checkout', |
| 738 | + 'entry': 'bash -c "echo ${PRE_COMMIT_TO_REF}"', |
| 739 | + 'language': 'system', |
| 740 | + 'always_run': True, |
| 741 | + 'verbose': True, |
| 742 | + 'stages': ['post-checkout'], |
| 743 | + }], |
| 744 | + }, |
| 745 | + {'repo': 'meta', 'hooks': [{'id': 'identity'}]}, |
| 746 | + ] |
743 | 747 | write_config(path, config) |
744 | 748 | with cwd(path): |
745 | 749 | cmd_output('git', 'add', '.') |
746 | 750 | git_commit() |
| 751 | + |
| 752 | + # add a file only on `feature`, it should not be passed to hooks |
| 753 | + cmd_output('git', 'checkout', '-b', 'feature') |
| 754 | + open('some_file', 'a').close() |
| 755 | + cmd_output('git', 'add', '.') |
| 756 | + git_commit() |
| 757 | + cmd_output('git', 'checkout', 'master') |
| 758 | + |
747 | 759 | install(C.CONFIG_FILE, store, hook_types=['post-checkout']) |
748 | | - retc, _, stderr = cmd_output('git', 'checkout', '-b', 'feature') |
| 760 | + retc, _, stderr = cmd_output('git', 'checkout', 'feature') |
| 761 | + assert stderr is not None |
749 | 762 | assert retc == 0 |
750 | | - _, head, _ = cmd_output('git', 'rev-parse', 'HEAD') |
751 | | - assert head in str(stderr) |
| 763 | + assert git.head_rev(path) in stderr |
| 764 | + assert 'some_file' not in stderr |
752 | 765 |
|
753 | 766 |
|
754 | 767 | def test_prepare_commit_msg_integration_failing( |
|
0 commit comments