Update AStyleHelper to only format changed files
This commit is contained in:
parent
13b63bb2d4
commit
2223a7f10b
Binary file not shown.
|
@ -3,31 +3,46 @@
|
||||||
# Simple script to auto-format every source file before committing.
|
# Simple script to auto-format every source file before committing.
|
||||||
#
|
#
|
||||||
|
|
||||||
#check if the formatter is present
|
# Check if the formatter is present
|
||||||
if [ ! -f ./.github/format/AStyleHelper.exe ]; then
|
if [ ! -f .github/format/AStyleHelper.exe ]; then
|
||||||
echo "AStyleHelper not found!"
|
echo "AStyleHelper not found!"
|
||||||
exit 0
|
exit 0
|
||||||
fi
|
fi
|
||||||
|
|
||||||
#format the code
|
# Get stamp file epoch (default to 0)
|
||||||
"./.github/format/AStyleHelper.exe" Silent
|
STAMP_EPOCH=$(date -u -r .git/AStyleHelper.stamp +%s 2>/dev/null)
|
||||||
|
STAMP_EPOCH=${STAMP_EPOCH:-0}
|
||||||
|
|
||||||
#exit when nothing needs to be done
|
# If the HEAD is newer than the stamp (we switched branches), set stamp to 0
|
||||||
if [ $? == 0 ]; then
|
if [ $(date -u -r .git/HEAD +%s 2>/dev/null) -gt $STAMP_EPOCH ]; then
|
||||||
|
echo "AStyleHelper: branch switched, performing full formatting"
|
||||||
|
STAMP_EPOCH=0
|
||||||
|
fi
|
||||||
|
|
||||||
|
# Format the code
|
||||||
|
".github/format/AStyleHelper.exe" Silent $STAMP_EPOCH
|
||||||
|
FORMAT_STATUS=$?
|
||||||
|
|
||||||
|
# Touch the stamp file to indicate when the last formatting was done
|
||||||
|
touch .git/AStyleHelper.stamp
|
||||||
|
|
||||||
|
# Exit when nothing needs to be done
|
||||||
|
if [ $FORMAT_STATUS -eq 0 ]; then
|
||||||
|
echo "AStyleHelper: no formatting needed"
|
||||||
exit 0
|
exit 0
|
||||||
fi
|
fi
|
||||||
|
|
||||||
#stage the formatted files (when staged in this commit)
|
# Stage the formatted files (when staged in this commit)
|
||||||
gitFiles=$(git diff-index --name-only --cached HEAD)
|
GIT_FILES=$(git diff-index --name-only --cached HEAD)
|
||||||
if [[ -n "${gitFiles}" ]]; then
|
if [[ -n "$GIT_FILES" ]]; then
|
||||||
for fname in $gitFiles; do
|
for GIT_FILE in $GIT_FILES; do
|
||||||
git add --all -- "${fname}"
|
git add --all -- "$GIT_FILE"
|
||||||
done
|
done
|
||||||
fi
|
fi
|
||||||
|
|
||||||
#cancel commit if the changes were undone by the formatting
|
# Cancel commit if the changes were undone by the formatting
|
||||||
gitFiles=$(git diff-index --name-only --cached HEAD)
|
GIT_FILES=$(git diff-index --name-only --cached HEAD)
|
||||||
if [ -z "$gitFiles" ]; then
|
if [ -z "$GIT_FILES" ]; then
|
||||||
"./.github/AStyleHelper.exe" "After formatting, no files were staged..."
|
".github/AStyleHelper.exe" "After formatting, no files were staged..."
|
||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
|
|
Loading…
Reference in New Issue