Print filenames that need to be reformatted (#386)

* Print filenames that need to be reformatted

Print the names of all java files that need reformatting during the check and
reformat operations.
This commit is contained in:
Michael Muller 2019-11-26 13:20:27 -05:00 committed by GitHub
parent 961d7e88f4
commit 28499d23a0
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -41,6 +41,16 @@ where:
SCRIPT_DIR="$(realpath $(dirname $0))"
function showNoncompliantFiles() {
local forkPoint="$1"
local message="$2"
git diff -U0 ${forkPoint} | \
${SCRIPT_DIR}/google-java-format-diff.py -p1 | \
awk -v "message=$message" \
'/\+\+\+ ([^ ]*)/ { print message $2 }' 1>&2
}
function callGoogleJavaFormatDiff() {
local forkPoint
forkPoint=$(git merge-base --fork-point origin/master)
@ -48,10 +58,12 @@ function callGoogleJavaFormatDiff() {
local callResult
case "$1" in
"check")
showNoncompliantFiles "$forkPoint" "\033[1mNeeds formatting: "
callResult=$(git diff -U0 ${forkPoint} | \
${SCRIPT_DIR}/google-java-format-diff.py -p1 | wc -l)
;;
"format")
showNoncompliantFiles "$forkPoint" "\033[1mReformatting: "
callResult=$(git diff -U0 ${forkPoint} | \
${SCRIPT_DIR}/google-java-format-diff.py -p1 -i)
;;
@ -60,6 +72,7 @@ function callGoogleJavaFormatDiff() {
${SCRIPT_DIR}/google-java-format-diff.py -p1)
;;
esac
echo -e "\033[0m" 1>&2
echo "${callResult}"
exit 0
}