nim-codex/tools/scripts/git_pre_commit_format.sh
Adam Uhlíř e5df8c50d3
style: nph formatting (#1067)
* style: nph setup

* chore: formates codex/ and tests/ folder with nph 0.6.1
2025-01-21 20:54:46 +00:00

17 lines
456 B
Bash
Executable File

#!/bin/sh
echo "Formatting changed files with pre-commit hook"
# Regexp for grep to only choose some file extensions for formatting
exts="\.\(nim\|nims\)$"
# Build nph lazily
make build-nph || (1>&2 echo "failed to build nph. Pre-commit formatting will not be done."; exit 0)
# Format staged files
git diff --cached --name-only --diff-filter=ACMR | grep "$exts" | while read file; do
echo "Formatting $file"
make nph/"$file"
git add "$file"
done