Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/joelparkerhenderson/git-hooks
Git hooks
https://github.com/joelparkerhenderson/git-hooks
Last synced: about 2 months ago
JSON representation
Git hooks
- Host: GitHub
- URL: https://github.com/joelparkerhenderson/git-hooks
- Owner: joelparkerhenderson
- Created: 2020-04-14T23:24:17.000Z (over 4 years ago)
- Default Branch: main
- Last Pushed: 2023-09-15T19:38:13.000Z (about 1 year ago)
- Last Synced: 2024-05-02T00:54:38.906Z (5 months ago)
- Language: Shell
- Size: 26.4 KB
- Stars: 7
- Watchers: 3
- Forks: 5
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Contributing: CONTRIBUTING.md
- Code of conduct: CODE_OF_CONDUCT.md
- Codeowners: CODEOWNERS
Awesome Lists containing this project
README
# Git hooks
This repo has example git hooks and helpers.
For example our git hook named `pre-commit` runs these:
```sh
.git/hooks/helpers/file-name-must-not-start-with "tmp"
.git/hooks/helpers/file-name-must-not-end-with ".env"
.git/hooks/helpers/file-name-must-not-contain "unversioned"
.git/hooks/helpers/file-text-must-end-with-newline
```Then runs any scripts in the corresponding directory:
```sh
.git/hooks/pre-commit.d
```The git hooks print messages such as:
```sh
File `tmp/example.txt` name must not start with `tmp`
File `environments/example.env` name must not end with `.env`
File `vendor/unversioned/example.bin` name must not contain "unversioned"
File `doc/example.txt` text must end with newline
```The git hooks can use any language, such as this example using POSIX shell:
```sh
#!/bin/sh
set -euf
target="$1"
exit_code=0for file_name in $(git diff --cached --name-only); do
case "$file_name"
"$target"*)
exit_code=1
printf %s\\n "File \`$file_name\` name must not start with \`$target\`."
;;
esac
doneexit $exit_code
```