diff --git a/pre_commit_hooks/no_commit_to_branch.py b/pre_commit_hooks/no_commit_to_branch.py index a97b103..4aa3535 100644 --- a/pre_commit_hooks/no_commit_to_branch.py +++ b/pre_commit_hooks/no_commit_to_branch.py @@ -9,7 +9,7 @@ from pre_commit_hooks.util import cmd_output def is_on_branch(protected): branch = cmd_output('git', 'symbolic-ref', 'HEAD') chunks = branch.strip().split('/') - return chunks[2] == protected + return '/'.join(chunks[2:]) == protected def main(argv=[]): diff --git a/tests/check_no_commit_to_branch_test.py b/tests/check_no_commit_to_branch_test.py index e8b09fd..99af938 100644 --- a/tests/check_no_commit_to_branch_test.py +++ b/tests/check_no_commit_to_branch_test.py @@ -12,6 +12,18 @@ def test_other_branch(temp_git_dir): assert is_on_branch('master') is False +def test_multi_branch(temp_git_dir): + with temp_git_dir.as_cwd(): + cmd_output('git', 'checkout', '-b', 'another/branch') + assert is_on_branch('master') is False + + +def test_multi_branch_fail(temp_git_dir): + with temp_git_dir.as_cwd(): + cmd_output('git', 'checkout', '-b', 'another/branch') + assert is_on_branch('another/branch') is True + + def test_master_branch(temp_git_dir): with temp_git_dir.as_cwd(): assert is_on_branch('master') is True