no-commit-to-branch does not respect excludes
See original GitHub issueReproduction steps .pre-commit-config.yaml:
repos:
- repo: 'https://github.com/pre-commit/pre-commit-hooks'
rev: 'v3.1.0'
hooks:
- id: 'no-commit-to-branch'
args: ['--branch', 'master']
exclude: 'foo.txt'
git status:
$ git status
On branch master
No commits yet
Changes to be committed:
(use "git rm --cached <file>..." to unstage)
new file: foo.txt
Output:
$ pre-commit run
Don't commit to branch...................................................Failed
- hook id: no-commit-to-branch
- exit code: 1
Appreciate this might be somewhere between a bug and a feature request. The particular use-case I’m trying to address concerns a repo with a structure of:
.
├── application-code
│ └── code-which-must-be-peer-reviewed
└── integration-test-code
└── test-code-which-can-go-straight-to-master
So I was expecting the following to work:
- id: 'no-commit-to-branch'
args: ['--branch', 'master']
exclude: '^integration-test-code/'
This also applies to exclude_types
. I believe the fix would be just to revert https://github.com/pre-commit/pre-commit-hooks/commit/66eb9d3aec1237b5aae3785b22da6b2f699b5d54 (EDIT: and drop the always_run
) but I’m sure there was a good reason for that change, so wanted to check that before raising a PR. Many thanks!
Issue Analytics
- State:
- Created 3 years ago
- Comments:5 (5 by maintainers)
Top Results From Across the Web
edevau/home-assistant-core - Gitea
**Your PR cannot be merged unless tests pass** - [x] There is no ... Exclude acmeda integration from coverage check as it relies...
Read more >pre-commit-hooks - GithubHelp
Note that this hook WILL remove blank lines and does NOT respect any comments. ... Note that no-commit-to-branch is configured by default to...
Read more >Some out-of-the-box hooks for pre-commit - PythonRepo
Note that no-commit-to-branch is configured by default to always_run . As a result, it will ignore any setting of files , exclude ,...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
would you like to send a PR with some documentation updates for the next person? maybe some quick blurb about ignoring
files
/exclude
/types
/exclude_types
unless you setalways_run: false
(and the limitation about empty commits)Sounds good to me! Done in #501