no-commit-to-branch: Add 'main' to branches blocked by default by ndevenish · Pull Request #565 · pre-commit/pre-commit-hooks
It's becoming more common to have the primary git branch be called main instead of master 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 and main 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 global init.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.