fix(husky): format staged rust files

This commit is contained in:
t8y2 committed 2026-05-30 12:47:55 +08:00
1 parent 4f3a72aa1b
commit 9b4115a1e9
1 file changed
+3 -3
+3 -3
View File
@@ -4,10 +4,10 @@ npx lint-staged
TOPLEVEL=$(git rev-parse --show-toplevel)
format_staged_rust() {
local dir="$1"
local staged=""
staged=$(git diff --staged --name-only --diff-filter=ACM -- ":(top,literal)$dir/*.rs" ":(top,literal)$dir/**/*.rs" 2>/dev/null)
dir="$1"
staged=$(git diff --staged --name-only --diff-filter=ACM -- "$dir" | grep '\.rs$' || true)
if [ -n "$staged" ]; then
echo "Formatting staged Rust files in $dir"
cargo fmt --manifest-path "$TOPLEVEL/$dir/Cargo.toml"
echo "$staged" | while IFS= read -r f; do
git add "$TOPLEVEL/$f" 2>/dev/null || true