Skip to content

Instantly share code, notes, and snippets.

@EtherZa
Created August 12, 2019 02:53
Show Gist options
  • Save EtherZa/581d9276336353838b2c939f9554d479 to your computer and use it in GitHub Desktop.
Save EtherZa/581d9276336353838b2c939f9554d479 to your computer and use it in GitHub Desktop.
Format c# with dotnet-format with pre-commit hook
#!/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
@ryanbuening
Copy link

@EtherZa are there instructions or a sample project on how to use that with dotnet format?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment