OpenFPGA/dev/check-format.sh

35 lines
877 B
Bash
Raw Normal View History

2022-10-06 20:26:06 -05:00
#!/usr/bin/env bash
clean=$(git status -s -uno | wc -l) #Short ignore untracked
2022-10-06 21:13:13 -05:00
file_pattern="*.cpp *.c *.hpp *.h *.py *.xml"
2022-10-06 20:26:06 -05:00
if [ $clean -ne 0 ]; then
echo "Current working tree was not clean! This tool only works on clean checkouts"
exit 2
else
echo "Code Formatting Check"
echo "====================="
make format"$1" > /dev/null 2>&1
2022-10-06 21:13:13 -05:00
valid_format=$(git diff ${file_pattern}| wc -l)
2022-10-06 20:26:06 -05:00
if [ $valid_format -ne 0 ]; then
echo "FAILED"
echo ""
echo "You *must* make the following changes to match the formatting style"
echo "-------------------------------------------------------------------"
echo ""
2022-10-06 21:13:13 -05:00
git diff ${file_pattern}
2022-10-06 20:26:06 -05:00
echo ""
echo "Run 'make format$1' to apply these changes"
git reset --hard > /dev/null
exit 1
else
echo "OK"
fi
fi
exit 0