mirror of
https://github.com/pre-commit/pre-commit-hooks.git
synced 2026-04-09 04:54:16 +00:00
no-commit-to-branch: Default to both master and main
This commit is contained in:
parent
51e14fcc97
commit
3abbd4785c
3 changed files with 9 additions and 2 deletions
|
|
@ -140,7 +140,7 @@ Assert that files in tests/ end in `_test.py`.
|
||||||
#### `no-commit-to-branch`
|
#### `no-commit-to-branch`
|
||||||
Protect specific branches from direct checkins.
|
Protect specific branches from direct checkins.
|
||||||
- Use `args: [--branch, staging, --branch, master]` to set the branch.
|
- 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
|
- `-b` / `--branch` may be specified multiple times to protect multiple
|
||||||
branches.
|
branches.
|
||||||
- `-p` / `--pattern` can be used to protect branches that match a supplied regex
|
- `-p` / `--pattern` can be used to protect branches that match a supplied regex
|
||||||
|
|
|
||||||
|
|
@ -38,7 +38,7 @@ def main(argv: Optional[Sequence[str]] = None) -> int:
|
||||||
)
|
)
|
||||||
args = parser.parse_args(argv)
|
args = parser.parse_args(argv)
|
||||||
|
|
||||||
protected = frozenset(args.branch or ('master',))
|
protected = frozenset(args.branch or ('master', 'main'))
|
||||||
patterns = frozenset(args.pattern or ())
|
patterns = frozenset(args.pattern or ())
|
||||||
return int(is_on_branch(protected, patterns))
|
return int(is_on_branch(protected, patterns))
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -67,3 +67,10 @@ def test_not_on_a_branch(temp_git_dir):
|
||||||
cmd_output('git', 'checkout', head)
|
cmd_output('git', 'checkout', head)
|
||||||
# we're not on a branch!
|
# we're not on a branch!
|
||||||
assert main(()) == 0
|
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
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue