1

Is there already a pre-commit.com hook to reject commit if a file contains a specific string?

I know how to do this with a git pre-commit hook: https://stackoverflow.com/a/26836281/633961

But I would like to go the pre-commit.com way because this would streamline my way to a way which is done by other developers.

For example I would like to use the same string which other people use, too.

guettli
  • 25,042
  • 81
  • 346
  • 663

1 Answers1

3

The easiest way is to use a language: pygrep hook. This implements a regex matching againsta file

pygrep is especially useful for a repo: local hook which lives directly in your repository's .pre-commit-config.yaml file

an example which forbids DONTSHIP:

-   repo: local
    hooks:
    -   id: dontship
        name: DONTSHIP check
        entry: DONTSHIP
        language: pygrep
        types: [text]

disclaimer: I'm the creator of pre-commit

anthony sottile
  • 61,815
  • 15
  • 148
  • 207