generated from OSGP/gxf-service-template
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #41 from OSGP/feature/FDP-2318-spotless-pre-commit…
…-hook FDP-2318: Spotless pre-commit hook
- Loading branch information
Showing
2 changed files
with
44 additions
and
1 deletion.
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,33 @@ | ||
#!/bin/bash | ||
echo "*********************************************************" | ||
echo "Running git pre-commit hook. Running Spotless Apply... " | ||
echo "*********************************************************" | ||
|
||
# Gather the staged files - to make sure changes are saved only for these files. | ||
stagedFiles=$(git diff --staged --name-only) | ||
|
||
# run spotless apply | ||
./gradlew spotlessApply | ||
|
||
status=$? | ||
|
||
if [ "$status" = 0 ] ; then | ||
echo "Static analysis found no problems." | ||
# Add staged file changes to git | ||
for file in $stagedFiles; do | ||
if test -f "$file"; then | ||
git add $file | ||
fi | ||
done | ||
#Exit | ||
exit 0 | ||
else | ||
echo "*********************************************************" | ||
echo " ******************************************** " | ||
echo 1>&2 "Spotless Apply found violations it could not fix." | ||
echo "Run spotless apply in your terminal and fix the issues before trying to commit again." | ||
echo " ******************************************** " | ||
echo "*********************************************************" | ||
#Exit | ||
exit 1 | ||
fi |