chore: apply project standards templates
This commit is contained in:
@@ -0,0 +1,21 @@
|
||||
# Git Hooks
|
||||
|
||||
This repository standard uses a project-local hooks directory:
|
||||
|
||||
- `.githooks/pre-commit`
|
||||
|
||||
Activate it once per repository:
|
||||
|
||||
```sh
|
||||
git config core.hooksPath .githooks
|
||||
```
|
||||
|
||||
The pre-commit hook validates for staged `.sh` files:
|
||||
|
||||
- executable bit in Git index (`100755`)
|
||||
- LF line endings (no CRLF)
|
||||
|
||||
The pre-commit hook also validates staged `.md` files with `markdownlint`:
|
||||
|
||||
- no `markdownlint` errors or problems
|
||||
- requires `markdownlint` CLI in PATH (for example via `npm install --global markdownlint-cli`)
|
||||
@@ -0,0 +1,40 @@
|
||||
#!/usr/bin/env sh
|
||||
set -eu
|
||||
|
||||
failed=0
|
||||
cr=$(printf '\r')
|
||||
|
||||
staged_shell_files=$(git diff --cached --name-only --diff-filter=ACMR | grep -E '\.sh$' || true)
|
||||
staged_markdown_files=$(git diff --cached --name-only --diff-filter=ACMR | grep -E '\.md$' || true)
|
||||
|
||||
for file in $staged_shell_files; do
|
||||
mode=$(git ls-files --stage -- "$file" | awk '{print $1}')
|
||||
if [ "$mode" != "100755" ]; then
|
||||
echo "ERROR: $file is not executable in Git index. Run: git add --chmod=+x $file" >&2
|
||||
failed=1
|
||||
fi
|
||||
|
||||
if git show ":$file" | grep -q "$cr"; then
|
||||
echo "ERROR: $file contains CRLF in staged content. Use LF line endings." >&2
|
||||
failed=1
|
||||
fi
|
||||
done
|
||||
|
||||
if [ -n "$staged_markdown_files" ]; then
|
||||
if ! command -v markdownlint >/dev/null 2>&1; then
|
||||
echo "ERROR: markdownlint is required to validate staged Markdown files (.md)." >&2
|
||||
echo "Install with npm: npm install --global markdownlint-cli" >&2
|
||||
failed=1
|
||||
else
|
||||
# Validate the staged markdown files currently present in the working tree.
|
||||
# This keeps the hook simple and fast for standard project usage.
|
||||
if ! markdownlint $staged_markdown_files; then
|
||||
failed=1
|
||||
fi
|
||||
fi
|
||||
fi
|
||||
|
||||
if [ "$failed" -ne 0 ]; then
|
||||
echo "Pre-commit check failed." >&2
|
||||
exit 1
|
||||
fi
|
||||
Reference in New Issue
Block a user