pre-commit doesn't modify files, just checks foramtting

This commit is contained in:
Adam Wright
2016-02-15 20:01:51 -08:00
committed by Adam Wright
parent 07c052a1c1
commit f2328d200e

View File

@@ -51,23 +51,6 @@ else
printf "${SUCCESS}\n"
fi
function fmt() {
printf "${PREFIX} Running rustfmt on $1 ... "
(cd $1 && cargo-fmt -q)
FMTRESULT=$?
if [ "${TARPC_SKIP_RUSTFMT}" == 1 ]; then
printf "${SKIPPED}\n"
elif [ ${FMTRESULT} != 0 ]; then
FAILED=1
printf "${FAILURE}\n"
else
printf "${SUCCESS}\n"
fi
}
fmt tarpc
fmt tarpc_examples
printf "${PREFIX} Checking for bad whitespace ... "
git diff-index --check --cached $against -- &>/dev/null
if [ "$?" != 0 ]; then
@@ -77,6 +60,28 @@ else
printf "${SUCCESS}\n"
fi
printf "${PREFIX} Checking formatting ... "
FMTRESULT=0
for file in $(git diff --name-only --cached);
do
if [ ${file: -3} == ".rs" ]; then
HASH=$(shasum $file)
NEW_HASH=$(rustfmt --write-mode=display $file | shasum)
if [ "${HASH}" != "${NEW_HASH}" ]; then
FMTRESULT=1
fi
fi
done
if [ "${TARPC_SKIP_RUSTFMT}" == 1 ]; then
printf "${SKIPPED}\n"$?
elif [ ${FMTRESULT} != 0 ]; then
FAILED=1
printf "${FAILURE}\n"
else
printf "${SUCCESS}\n"
fi
if [ ${FAILED} != 0 ]; then
exit 1
fi