diff --git a/private_dot_config/git-hooks/executable_pre-commit b/private_dot_config/git-hooks/executable_pre-commit index bcb57d9..d5d7cc9 100644 --- a/private_dot_config/git-hooks/executable_pre-commit +++ b/private_dot_config/git-hooks/executable_pre-commit @@ -8,13 +8,15 @@ else 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: .*/version: $now/" "$file" - sed -i "s/Version: .*/Version: $now/" "$file" + sed -i "s/version: 2023-01-16 15:36 + sed -i "s/Version: 2023-01-16 15:36 git add "$file" } @@ -41,6 +43,22 @@ checkJavaFormat() 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 @@ -52,6 +70,9 @@ for FILE in $(exec git diff --cached --name-only --diff-filter=ACMR) ; do checkJavaFormat "$FILE" git add "$FILE" ;; + *.rs) + checkRustFormat + ;; *.sh|*.profile) checkBash "$FILE" ;;