Format c++ files using clang-format

Add git pre-commit hooks to help with automatic formatting.
This commit is contained in:
Leroy Hopson 2021-06-06 19:58:50 +07:00 committed by Leroy Hopson
parent 99989d19e4
commit 6e455738b8
10 changed files with 981 additions and 760 deletions

23
misc/hooks/pre-commit-gdformat Executable file
View file

@ -0,0 +1,23 @@
#! /usr/bin/env nix-shell
#! nix-shell -i sh -p python38
GDTOOLKIT_VERSION=f5e2746d146200ec07ac6acb6fb378fd4c64f3f0
FILES=$(git diff --cached --name-only --diff-filter=ACMR | grep '\.gd$' | sed 's| |\\ |g')
[ -z "$FILES" ] && exit 0
# Setup GDScript Toolkit.
if [ ! -f .venv/bin/activate ] || ! source .venv/bin/activate; then
python -m venv .venv && source .venv/bin/activate;
fi
if ! gdformat --version; then
pip install git+git://github.com/Scony/godot-gdscript-toolkit@${gdtoolkit_version};
fi
# Format all selected files.
echo "$FILES" | xargs gdformat
# Add back the formatted files to staging.
echo "$FILES" | xargs git add
exit 0