1 parent 51e14fc commit 3abbd47Copy full SHA for 3abbd47
3 files changed
README.md
@@ -140,7 +140,7 @@ Assert that files in tests/ end in `_test.py`.
140
#### `no-commit-to-branch`
141
Protect specific branches from direct checkins.
142
- Use `args: [--branch, staging, --branch, master]` to set the branch.
143
- `master` is the default if no branch argument is set.
+ Both `master` and `main` are protected by default if no branch argument is set.
144
- `-b` / `--branch` may be specified multiple times to protect multiple
145
branches.
146
- `-p` / `--pattern` can be used to protect branches that match a supplied regex
pre_commit_hooks/no_commit_to_branch.py
@@ -38,7 +38,7 @@ def main(argv: Optional[Sequence[str]] = None) -> int:
38
)
39
args = parser.parse_args(argv)
40
41
- protected = frozenset(args.branch or ('master',))
+ protected = frozenset(args.branch or ('master', 'main'))
42
patterns = frozenset(args.pattern or ())
43
return int(is_on_branch(protected, patterns))
44
tests/no_commit_to_branch_test.py
@@ -67,3 +67,10 @@ def test_not_on_a_branch(temp_git_dir):
67
cmd_output('git', 'checkout', head)
68
# we're not on a branch!
69
assert main(()) == 0
70
+
71
72
+@pytest.mark.parametrize('branch_name', ('master', 'main'))
73
+def test_default_branch_names(temp_git_dir, branch_name):
74
+ with temp_git_dir.as_cwd():
75
+ cmd_output('git', 'checkout', '-b', branch_name)
76
+ assert main(()) == 1
0 commit comments