mirror of
https://github.com/pre-commit/pre-commit-hooks.git
synced 2026-04-14 14:34:45 +00:00
Adding support for branches with a slash in them.
This commit is contained in:
parent
28c3288ba8
commit
878e45021d
2 changed files with 13 additions and 1 deletions
|
|
@ -9,7 +9,7 @@ from pre_commit_hooks.util import cmd_output
|
||||||
def is_on_branch(protected):
|
def is_on_branch(protected):
|
||||||
branch = cmd_output('git', 'symbolic-ref', 'HEAD')
|
branch = cmd_output('git', 'symbolic-ref', 'HEAD')
|
||||||
chunks = branch.strip().split('/')
|
chunks = branch.strip().split('/')
|
||||||
return chunks[2] == protected
|
return '/'.join(chunks[2:]) == protected
|
||||||
|
|
||||||
|
|
||||||
def main(argv=[]):
|
def main(argv=[]):
|
||||||
|
|
|
||||||
|
|
@ -12,6 +12,18 @@ def test_other_branch(temp_git_dir):
|
||||||
assert is_on_branch('master') is False
|
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):
|
def test_master_branch(temp_git_dir):
|
||||||
with temp_git_dir.as_cwd():
|
with temp_git_dir.as_cwd():
|
||||||
assert is_on_branch('master') is True
|
assert is_on_branch('master') is True
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue