Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

no-commit-to-branch: Add 'main' to branches blocked by default #565

Merged
merged 1 commit into from
Mar 4, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ Assert that files in tests/ end in `_test.py`.
#### `no-commit-to-branch`
Protect specific branches from direct checkins.
- Use `args: [--branch, staging, --branch, master]` to set the branch.
`master` is the default if no branch argument is set.
Both `master` and `main` are protected by default if no branch argument is set.
- `-b` / `--branch` may be specified multiple times to protect multiple
branches.
- `-p` / `--pattern` can be used to protect branches that match a supplied regex
Expand Down
2 changes: 1 addition & 1 deletion pre_commit_hooks/no_commit_to_branch.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ def main(argv: Optional[Sequence[str]] = None) -> int:
)
args = parser.parse_args(argv)

protected = frozenset(args.branch or ('master',))
protected = frozenset(args.branch or ('master', 'main'))
patterns = frozenset(args.pattern or ())
return int(is_on_branch(protected, patterns))

Expand Down
7 changes: 7 additions & 0 deletions tests/no_commit_to_branch_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,3 +67,10 @@ def test_not_on_a_branch(temp_git_dir):
cmd_output('git', 'checkout', head)
# we're not on a branch!
assert main(()) == 0


@pytest.mark.parametrize('branch_name', ('master', 'main'))
def test_default_branch_names(temp_git_dir, branch_name):
with temp_git_dir.as_cwd():
cmd_output('git', 'checkout', '-b', branch_name)
assert main(()) == 1