From 032e2492c41d7c7bc0b0ba20c87c2419c4344111 Mon Sep 17 00:00:00 2001 From: Daniel Savu <23065004+daniel-savu@users.noreply.github.com> Date: Tue, 8 Aug 2023 14:33:49 +0100 Subject: [PATCH] fix: only run cargo fmt hook when rs files changed (#2620) ### Description The `cargo fmt` pre-commit hook runs regardless of whether any `.rs` files have changed and this is interfering with unrelated workflows. This reduces the scope of the hook to commits with nonempty rust diffs. ### Drive-by changes ### Related issues ### Backward compatibility ### Testing --- .husky/pre-commit | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/.husky/pre-commit b/.husky/pre-commit index 0f04b859c..ea48d6b17 100755 --- a/.husky/pre-commit +++ b/.husky/pre-commit @@ -2,4 +2,9 @@ . "$(dirname -- "$0")/_/husky.sh" yarn lint-staged -cargo fmt --all --check --manifest-path rust/Cargo.toml + +# if any *.rs files have changed +if git diff --staged --exit-code --name-only | grep -q -E ".*\.rs$"; then + echo "Running cargo fmt pre-commit hook" + cargo fmt --all --check --manifest-path rust/Cargo.toml +fi