forked from criteo/cuttle
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgit-init-precommit-hook.sh
More file actions
executable file
·29 lines (29 loc) · 1.01 KB
/
git-init-precommit-hook.sh
File metadata and controls
executable file
·29 lines (29 loc) · 1.01 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
#!/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"
echo -e "\e[0;33m prettier-eslint RUNNING \e[0m"
npm run format-diff
RESULT=$?
if [ ${RESULT} -ne 0 ]; then
echo -e "\e[0;31m prettier-eslint FAILED \e[0m"
exit ${RESULT}
fi
echo -e "\e[0;32m prettier-eslint SUCCEEDED \e[0m"
echo -e "\e[0;33m Add formating to commit\e[0m"
git add $(git diff-index --cached HEAD --name-only --diff-filter=d)
echo -e "\e[0;32m Add formating SUCCEEDED\e[0m"
exit 0
' > .git/hooks/pre-commit
chmod +x .git/hooks/pre-commit