no-commit-to-branch: Add 'main' to branches blocked by default #565
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
It's becoming more common to have the primary git branch be called
main
instead ofmaster
now. With GitHub now making it the default and making it easier to transition across, we've started noticing it more in other repositories, and started transferring our repositories over to it.However, a stage that we missed in several cases was updating the pre-commit hook for
no-commit-to-branch
to block the new name, as we had relied on the default behaviour before.This patch updates the default behaviour so both
master
andmain
are blocked by default.Along with this, I found that all of the tests for this hook failed by default on my machine - as part of moving my muscle memory I had set git's globalinit.defaultBranch=main
. This only seems to exist from 2.28, while pre-commit lists 2.24 as a requirement for tests - but git seems to ignore (or set but not use) unrecognised configurations, so this should be safe for all targets.Side note: I couldn't find any guidelines for what formatting you want in this repo, and flake8 complained about the now-longer git call in the test configuration, so I wrote it in black-style.