Skip to content

Commit 3abbd47

Browse files
committed
no-commit-to-branch: Default to both master and main
1 parent 51e14fc commit 3abbd47

File tree

3 files changed

+9
-2
lines changed

3 files changed

+9
-2
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -140,7 +140,7 @@ Assert that files in tests/ end in `_test.py`.
140140
#### `no-commit-to-branch`
141141
Protect specific branches from direct checkins.
142142
- Use `args: [--branch, staging, --branch, master]` to set the branch.
143-
`master` is the default if no branch argument is set.
143+
Both `master` and `main` are protected by default if no branch argument is set.
144144
- `-b` / `--branch` may be specified multiple times to protect multiple
145145
branches.
146146
- `-p` / `--pattern` can be used to protect branches that match a supplied regex

pre_commit_hooks/no_commit_to_branch.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ def main(argv: Optional[Sequence[str]] = None) -> int:
3838
)
3939
args = parser.parse_args(argv)
4040

41-
protected = frozenset(args.branch or ('master',))
41+
protected = frozenset(args.branch or ('master', 'main'))
4242
patterns = frozenset(args.pattern or ())
4343
return int(is_on_branch(protected, patterns))
4444

tests/no_commit_to_branch_test.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,3 +67,10 @@ def test_not_on_a_branch(temp_git_dir):
6767
cmd_output('git', 'checkout', head)
6868
# we're not on a branch!
6969
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

Comments
 (0)