-
-
Save simonauner/09d4e3241f26d2bd139261816e6c18f6 to your computer and use it in GitHub Desktop.
Format c# with dotnet-format with pre-commit hook
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/sh | |
# Modified from https://gist.github.com/EtherZa/581d9276336353838b2c939f9554d479 | |
# | |
# This script finds the files that are about to be committed, | |
# and runs dotnet format on them before adding them back to staging | |
# | |
# install dotnet-format: dotnet tool install -g dotnet-format | |
# make sure installed dotnet tools are on your path: | |
# export PATH="$PATH:$HOME/.dotnet/tools/" | |
# copy to .git/hooks/pre-commit and make executable | |
# | |
FILES=$(git diff --cached --name-only --diff-filter=ACM "*.cs") | |
[ -z "$FILES" ] && exit 0 | |
echo "Running dotnet format for staged files" | |
dotnet format --include $FILES | |
# Add back the modified files to staging | |
echo "$FILES" | xargs git add | |
echo "dotnet format done" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment