|
| 1 | +from __future__ import absolute_import |
| 2 | +from __future__ import unicode_literals |
| 3 | + |
| 4 | +from pre_commit_hooks.no_commit_to_branch import is_on_branch |
| 5 | +from pre_commit_hooks.no_commit_to_branch import main |
| 6 | +from pre_commit_hooks.util import cmd_output |
| 7 | + |
| 8 | + |
| 9 | +def test_other_branch(temp_git_dir): |
| 10 | + with temp_git_dir.as_cwd(): |
| 11 | + cmd_output('git', 'checkout', '-b', 'anotherbranch') |
| 12 | + assert is_on_branch('master') is False |
| 13 | + |
| 14 | + |
| 15 | +def test_multi_branch(temp_git_dir): |
| 16 | + with temp_git_dir.as_cwd(): |
| 17 | + cmd_output('git', 'checkout', '-b', 'another/branch') |
| 18 | + assert is_on_branch('master') is False |
| 19 | + |
| 20 | + |
| 21 | +def test_multi_branch_fail(temp_git_dir): |
| 22 | + with temp_git_dir.as_cwd(): |
| 23 | + cmd_output('git', 'checkout', '-b', 'another/branch') |
| 24 | + assert is_on_branch('another/branch') is True |
| 25 | + |
| 26 | + |
| 27 | +def test_master_branch(temp_git_dir): |
| 28 | + with temp_git_dir.as_cwd(): |
| 29 | + assert is_on_branch('master') is True |
| 30 | + |
| 31 | + |
| 32 | +def test_main_b_call(temp_git_dir): |
| 33 | + with temp_git_dir.as_cwd(): |
| 34 | + cmd_output('git', 'checkout', '-b', 'other') |
| 35 | + assert main(['-b', 'other']) == 1 |
| 36 | + |
| 37 | + |
| 38 | +def test_main_branch_call(temp_git_dir): |
| 39 | + with temp_git_dir.as_cwd(): |
| 40 | + cmd_output('git', 'checkout', '-b', 'other') |
| 41 | + assert main(['--branch', 'other']) == 1 |
| 42 | + |
| 43 | + |
| 44 | +def test_main_default_call(temp_git_dir): |
| 45 | + with temp_git_dir.as_cwd(): |
| 46 | + cmd_output('git', 'checkout', '-b', 'anotherbranch') |
| 47 | + assert main() == 0 |
0 commit comments