diff options
| author | xFrednet <xFrednet@gmail.com> | 2021-06-16 00:04:50 +0200 |
|---|---|---|
| committer | flip1995 <philipp.krones@embecosm.com> | 2021-06-25 11:16:59 +0200 |
| commit | 41bc0f4d4d3cdacc97de6c803ff7bdf1c120f315 (patch) | |
| tree | f35583e4e9434448906b34907408ab14eea1c1af | |
| parent | 0a5f28c4b0c78c030956afe77b7a5c0c3e33ef5b (diff) | |
| download | rust-41bc0f4d4d3cdacc97de6c803ff7bdf1c120f315.tar.gz rust-41bc0f4d4d3cdacc97de6c803ff7bdf1c120f315.zip | |
Adjust pre-commit script to readd files after formatting
| -rwxr-xr-x | util/etc/pre-commit.sh | 20 |
1 files changed, 19 insertions, 1 deletions
diff --git a/util/etc/pre-commit.sh b/util/etc/pre-commit.sh index 3c76e924b34..528f8953b25 100755 --- a/util/etc/pre-commit.sh +++ b/util/etc/pre-commit.sh @@ -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 |
