Adjust pre-commit script to readd files after formatting

This commit is contained in:
xFrednet 2021-06-16 00:04:50 +02:00 committed by flip1995
parent 0a5f28c4b0
commit 41bc0f4d4d
No known key found for this signature in database
GPG Key ID: 1CA0DF2AF59D68A5

View File

@ -1,3 +1,21 @@
#!/bin/sh
cargo dev fmt
# hide output
set -e
# Update lints
cargo dev update_lints
git add clippy_lints/src/lib.rs
# Formatting:
# Git will not automatically add the formatted code to the staged changes once
# fmt was executed. This collects all staged files rs files that are currently staged.
# They will later be added back.
#
# This was proudly stolen and adjusted from here:
# https://medium.com/@harshitbangar/automatic-code-formatting-with-git-66c3c5c26798
files=$( (git diff --cached --name-only --diff-filter=ACMR | grep -Ei "\.rs$") || true)
if [ ! -z "${files}" ]; then
cargo dev fmt
git add $(echo "$files" | paste -s -d " " -)
fi