92 lines
2.5 KiB
Bash
92 lines
2.5 KiB
Bash
#!/bin/bash
|
|
|
|
if git rev-parse --verify HEAD >/dev/null 2>&1
|
|
then
|
|
against=HEAD
|
|
else
|
|
# Initial commit: diff against an empty tree object
|
|
against=4b825dc642cb6eb9a060e54bf8d69288fbee4904
|
|
fi
|
|
|
|
RUST_CHECKED=false
|
|
|
|
checkBash()
|
|
{
|
|
local file="$1"
|
|
echo "checking for 'version' in $file"
|
|
now=$(date +'%Y-%m-%d %R')
|
|
sed -i "s/version: 2023-01-16 15:36
|
|
sed -i "s/Version: 2023-01-16 15:36
|
|
git add "$file"
|
|
}
|
|
|
|
# Set (Last Modified: <date>) in CHANGELOG.md
|
|
checkChangelog()
|
|
{
|
|
local file="$1"
|
|
echo "checking for 'Last Modified' in $file"
|
|
now=$(date +'%Y-%m-%d')
|
|
sed -i "s/\(Last Modified: .*\)/\(Last Modified: $now\)/" "$file"
|
|
git add "$file"
|
|
}
|
|
|
|
# Use google-java-format to force code guidelines
|
|
# https://github.com/google/google-java-format
|
|
checkJavaFormat()
|
|
{
|
|
local file="$1"
|
|
google-java-format --dry-run -aosp --set-exit-if-changed "$file"
|
|
retVal=$?
|
|
if [ $retVal -ne 0 ]; then
|
|
echo -e "\e[31mJava coding guidelines validation failed for $file \e[0m" >&2
|
|
exit $retVal
|
|
fi
|
|
}
|
|
|
|
checkRustFormat()
|
|
{
|
|
if [ "$RUST_CHECKED" == "false" ]; then
|
|
echo "checking rust code"
|
|
command -v cargo || { echo -e "\e[31mcargo not found!\e[0m"; exit 1; }
|
|
# diff=$(cargo fmt -- --check)
|
|
cargo fmt -- --check
|
|
result=$?
|
|
if [[ $result -ne 0 ]]; then
|
|
echo -e "\e[31mThere are some code style issues, run 'cargo fmt' first."
|
|
exit 1
|
|
fi
|
|
RUST_CHECKED=true
|
|
fi
|
|
}
|
|
|
|
for FILE in $(exec git diff --cached --name-only --diff-filter=ACMR) ; do
|
|
# Fix them!
|
|
case $FILE in
|
|
*.java)
|
|
echo "checking @version in $FILE"
|
|
now=$(date +'%d.%m.%Y %R')
|
|
sed -i "s/@version .*/@version $now/" "$FILE"
|
|
echo "checking code style in $FILE"
|
|
checkJavaFormat "$FILE"
|
|
git add "$FILE"
|
|
;;
|
|
*.rs)
|
|
checkRustFormat
|
|
;;
|
|
*.sh|*.profile)
|
|
checkBash "$FILE"
|
|
;;
|
|
CHANGELOG.md)
|
|
checkChangelog "$FILE"
|
|
;;
|
|
*.*|*/pre-commit)
|
|
echo "ignoring $FILE"
|
|
;;
|
|
*)
|
|
checkBash "$FILE"
|
|
;;
|
|
esac
|
|
done
|
|
|
|
exit
|