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))" 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() { function callGoogleJavaFormatDiff() {
local forkPoint local forkPoint
forkPoint=$(git merge-base --fork-point origin/master) forkPoint=$(git merge-base --fork-point origin/master)
@ -48,10 +58,12 @@ function callGoogleJavaFormatDiff() {
local callResult local callResult
case "$1" in case "$1" in
"check") "check")
showNoncompliantFiles "$forkPoint" "\033[1mNeeds formatting: "
callResult=$(git diff -U0 ${forkPoint} | \ callResult=$(git diff -U0 ${forkPoint} | \
${SCRIPT_DIR}/google-java-format-diff.py -p1 | wc -l) ${SCRIPT_DIR}/google-java-format-diff.py -p1 | wc -l)
;; ;;
"format") "format")
showNoncompliantFiles "$forkPoint" "\033[1mReformatting: "
callResult=$(git diff -U0 ${forkPoint} | \ callResult=$(git diff -U0 ${forkPoint} | \
${SCRIPT_DIR}/google-java-format-diff.py -p1 -i) ${SCRIPT_DIR}/google-java-format-diff.py -p1 -i)
;; ;;
@ -60,6 +72,7 @@ function callGoogleJavaFormatDiff() {
${SCRIPT_DIR}/google-java-format-diff.py -p1) ${SCRIPT_DIR}/google-java-format-diff.py -p1)
;; ;;
esac esac
echo -e "\033[0m" 1>&2
echo "${callResult}" echo "${callResult}"
exit 0 exit 0
} }