Created
August 12, 2019 02:53
-
-
Save EtherZa/581d9276336353838b2c939f9554d479 to your computer and use it in GitHub Desktop.
Format c# with dotnet-format with pre-commit hook
This file contains hidden or 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 sample: https://prettier.io/docs/en/precommit.html | |
# | |
# install dotnet-format: dotnet tool install -g dotnet-format | |
# copy to .git/hooks/pre-commit and make executable | |
# | |
FILES=$(git diff --cached --name-only --diff-filter=ACM "*.cs" | sed 's| |\\ |g') | |
[ -z "$FILES" ] && exit 0 | |
# Format all selected files | |
echo "$FILES" | cat | xargs | sed -e 's/ /,/g' | xargs dotnet-format --files | |
# Add back the modified files to staging | |
echo "$FILES" | xargs git add | |
exit 0 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
@EtherZa are there instructions or a sample project on how to use that with
dotnet format
?