Ignore checking formatting if no formatted files are staged (#1469)

I'm constantly harassed to follow the rules when I'm not doing anything
relevant.

This is an attempt to ameliorate that rather than `--no-verify` or just
disabling hooks altogether. 🍄 ☁️

Somebody might want to confirm `basename` is included with macOS.
This commit is contained in:
Michael Legleux
2024-06-18 10:11:06 -07:00
committed by GitHub
parent c795cf371a
commit 0cdc24023f

View File

@@ -5,6 +5,20 @@
# This script checks the format of the code and cmake files. # This script checks the format of the code and cmake files.
# In many cases it will automatically fix the issues and abort the commit. # In many cases it will automatically fix the issues and abort the commit.
no_formatted_directories_staged() {
staged_directories=$(git diff-index --cached --name-only HEAD | awk -F/ '{print $1}')
for sd in $staged_directories; do
if [[ "$sd" =~ ^(benchmark|cmake|src|tests)$ ]]; then
return 1
fi
done
return 0
}
if no_formatted_directories_staged ; then
exit 0
fi
echo "+ Checking code format..." echo "+ Checking code format..."
# paths to check and re-format # paths to check and re-format