diff --git a/tests/no_commit_to_branch_test.py b/tests/no_commit_to_branch_test.py index 1cb69e2..ccd83e4 100644 --- a/tests/no_commit_to_branch_test.py +++ b/tests/no_commit_to_branch_test.py @@ -1,5 +1,7 @@ from __future__ import annotations +from unittest.mock import patch + import pytest from pre_commit_hooks.no_commit_to_branch import _default_branch @@ -81,6 +83,14 @@ def test_default_branch_names(temp_git_dir, branch_name): assert main(()) == 1 +def test_default_branch_falls_back_when_empty_branch(tmpdir): + with patch( + 'pre_commit_hooks.no_commit_to_branch.cmd_output', + return_value='origin/', + ): + assert _default_branch() == frozenset({'master', 'main'}) + + def test_default_branch_detects_from_origin(tmpdir): remote = tmpdir.join('remote') cmd_output('git', 'init', '--', str(remote))