question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

no-commit-to-branch does not respect excludes

See original GitHub issue

Reproduction 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:closed
  • Created 3 years ago
  • Comments:5 (5 by maintainers)

github_iconTop GitHub Comments

1reaction
asottilecommented, Jun 18, 2020

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 set always_run: false (and the limitation about empty commits)

0reactions
marcjaycommented, Jun 19, 2020

Sounds good to me! Done in #501

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found