Files
PX4-Autopilot/Tools/astyle/check_code_style.sh
T
Balduin 385828fcb3 feat(astyle): add option to only format diff with respect to HEAD (#27122)
* feat(astyle): add make format_changed for diff only style fixes

`make format` is pretty slow because it always considers the entire
source tree. For developing on top of a clean state, considering only
files that differ from HEAD should be sufficient.

* docs(astyle): document new format_changed target
2026-04-19 18:30:21 -08:00

23 lines
755 B
Bash
Executable File

#!/usr/bin/env bash
FILE=$1
DIR=$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )
CHECK_FAILED=$(${DIR}/fix_code_style.sh --dry-run --formatted $FILE)
if [ -n "$CHECK_FAILED" ]; then
${DIR}/fix_code_style.sh --quiet < $FILE > $FILE.pretty
echo -e 'Formatting issue found in' $FILE
echo
git --no-pager diff --no-index --minimal --histogram --color=always $FILE $FILE.pretty | grep -vE -e "^.{,4}diff.*\.pretty.{,3}$" -e "^.{,4}--- a/.*$" -e "^.{,4}\+\+\+ b/.*$" -e "^.{,5}@@ .* @@.*$" -e "^.{,4}index .{10}\.\."
rm -f $FILE.pretty
echo
if [[ $PX4_ASTYLE_FIX -eq 1 ]]; then
${DIR}/fix_code_style.sh $FILE
else
echo 'to fix automatically run "make format", "make format_changed" or "./Tools/astyle/fix_code_style.sh' $FILE'"'
exit 1
fi
fi