Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/marick/pre-commit-hooks
Various git pre-commit or pre-push hooks using http://pre-commit.com/
https://github.com/marick/pre-commit-hooks
Last synced: 3 months ago
JSON representation
Various git pre-commit or pre-push hooks using http://pre-commit.com/
- Host: GitHub
- URL: https://github.com/marick/pre-commit-hooks
- Owner: marick
- License: unlicense
- Created: 2015-12-06T19:56:56.000Z (about 9 years ago)
- Default Branch: master
- Last Pushed: 2016-01-26T18:04:31.000Z (almost 9 years ago)
- Last Synced: 2024-05-08T19:03:32.319Z (9 months ago)
- Language: Ruby
- Size: 22.5 KB
- Stars: 11
- Watchers: 3
- Forks: 2
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Some `pre-commit` hooks I use
Various git pre-commit or pre-push hooks using http://pre-commit.com/.
1. Have Python's pip package manager installed. `brew install python`
2. `pip install pre-commit`
* If your version of `pre-commit` is less than 0.7, you need `pip install --upgrade pre-commit`
3. Put a `.pre-commit-config.yaml` at the root of a repo. See below.
4. `pre-commit install` # this installs pre-commit hooks
5. `pre-commit install --hook-type pre-push`If you have many repos to protect, you can use `install-hooks-in-repo`
to shorten steps 3-5. For example, if this repo has been cloned to
where you clone all your repos, you can protect them all like this:```
echo * | xargs -n1 pre-commit-hooks/install-hooks-in-repo pre-commit-hooks/dot-pre-commit-config.yaml.sample
````install-hooks-in-repo` will ignore non-directories and directories that aren't a git repo. It creates a log in `/tmp/install-hooks-in-repo.log`.
------------------
Below please find a short sample
`.pre-commit-config.yaml`. [dot-pre-commit-config.yaml.sample](https://github.com/marick/pre-commit-hooks/blob/master/dot-pre-commit-config.yaml.sample)
contains a longer one.```yaml
- repo: https://github.com/marick/pre-commit-hooks.git
sha: 569f6300cbbedf177c56eda8023350620998ff8f
stages: [commit, push]
hooks:
- id: only-branch-pushes
args: [prevent, ^(production|master)$]- id: prohibit-suspicious-patterns
args: [AKIA[[:alnum:]]{14}, --] # matches AWS keys- id: prohibit-suspicious-files
args: [".log$", --] # Don't commit log files. They can contain personal info.
```General notes:
* The `sha` can be updated to the repo's most recent version with `pre-commit autoupdate`.Notes on `only-branch-pushes`:
* Despite the name, `only-branch-pushes` actually can be applied during the `commit` stage (as it is here, according to the `stages` key). The name is not so good, but I'm too lazy to change it.
* The first argument must be `prevent`. The second is used in a
`=~`-style shell pattern match. That is, it's
compared like this:
if [[ "$branch" =~ $pattern ]]; then
If you want to prohibit just one branch, such as `production`, do this:
args: [prevent, ^production$]
Notes on `prohibit-suspicious-patterns`:
* The first arg searches for a pattern that matches AWS keys. I use it
as a
[suspenders and belt](http://www.investopedia.com/terms/b/belt-and-suspenders.asp)
strategy, alongside the `detect-aws-keys` hook from the
[standard repo](https://github.com/pre-commit/pre-commit-hooks).
* The patterns are
[Ruby regular expressions](http://ruby-doc.org/core-1.9.3/Regexp.html),
compiled with `Regexp.compile`.
* As such, you can't use the "outside-the-pattern" syntax for
modifiers like "match any case. That is, instead of `/TODO/i`, you
must use this:
args: ["(?i-mx:TODO)", --]* If you want to disable checking for a particular line, include `git commit ok` on that line. (You can replace the spaces with any *single* character.)
* In violation of the spirit of `pre-commit`, this hook assumes Ruby already exists on your system.Notes on `prohibit-suspicious-files`:
* Patterns are also Ruby regular expressions.
* The hook assumes Ruby already exists on your system.