Skip to content

Instantly share code, notes, and snippets.

@anvie
Last active June 18, 2021 15:29
Show Gist options
  • Save anvie/5a25c448b07774b5d78694e4652ba06f to your computer and use it in GitHub Desktop.
Save anvie/5a25c448b07774b5d78694e4652ba06f to your computer and use it in GitHub Desktop.
Git pre-commit script to run code formatter automatically
#!/bin/env bash
set -e
files=$((git diff --cached --name-only --diff-filter=ACMR | grep -Ei "\.rs$") || true)
if [ ! -z "${files}" ]; then
comma_files=$(echo "$files" | paste -s -d "," -)
make fmt
git add $(echo "$files" | paste -s -d " " -)
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment