Skip to content
This repository was archived by the owner on May 28, 2025. It is now read-only.

Commit 41bc0f4

Browse files
xFrednetflip1995
authored andcommitted
Adjust pre-commit script to readd files after formatting
1 parent 0a5f28c commit 41bc0f4

File tree

1 file changed

+19
-1
lines changed

1 file changed

+19
-1
lines changed

util/etc/pre-commit.sh

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,21 @@
11
#!/bin/sh
22

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

0 commit comments

Comments
 (0)