-
Notifications
You must be signed in to change notification settings - Fork 39
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add an init script of precommit hook with scalafmt. (#177)
* Add an init script of precommit hook with scalafmt. * Readme update about scalafmt.
- Loading branch information
eryshev
authored
Oct 2, 2017
1 parent
a5dbbd2
commit b4548d0
Showing
2 changed files
with
30 additions
and
4 deletions.
There are no files selected for viewing
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
#!/usr/bin/env bash | ||
# This script creates a pre-commit git hook that run scalafmt before each commit | ||
# http://scalameta.org/scalafmt/ | ||
# Need scalafmt installed in CLI mode. | ||
# Tested in Ubuntu's bash. | ||
[ -d .git/hooks/ ] || (echo "It's not a git directory";exit 1) | ||
[ -d .git/hooks/ ] && echo '#!/usr/bin/env bash | ||
echo -e "\e[0;33m Scalafmt RUNNING \e[0m" | ||
scalafmt --git true --diff-branch $(git branch | grep \* | cut -d " " -f2) | ||
RESULT=$? | ||
if [ ${RESULT} -ne 0 ]; then | ||
echo -e "\e[0;31m Scalafmt FAILED \e[0m" | ||
exit ${RESULT} | ||
fi | ||
echo -e "\e[0;32m Scalafmt SUCCEEDED \e[0m" | ||
exit 0 | ||
' > .git/hooks/pre-commit | ||
chmod +x .git/hooks/pre-commit |