Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added pre-commit hooks #421

Merged
merged 7 commits into from
May 20, 2022
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,14 @@ sonarqube {
}
}

// Install git hooks
task installLocalGitHook(type: Copy) {
from new File(rootProject.rootDir, 'scripts/pre-commit')
into new File(rootProject.rootDir, '.git/hooks')
fileMode 0775
}
build.dependsOn installLocalGitHook

subprojects {
apply plugin: "java"
apply plugin: "com.diffplug.spotless"
Expand Down
20 changes: 20 additions & 0 deletions scripts/pre-commit
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
#!/bin/sh

echo "****Running pre-commit hooks****"
# Keep staged changes and put unstaged aside for the hook (bypass hook to avoid recursion)
Zabuzard marked this conversation as resolved.
Show resolved Hide resolved
git commit --no-verify --message "WIP"
git stash -u
git reset --soft HEAD^

echo "**Applying spotless**"
if ! ./gradlew spotlessApply; then
# Restore unstaged changes
git stash pop -q
exit $?
fi
# Add Spotless changes
git add -A

# Restore unstaged changes
git stash pop -q
Zabuzard marked this conversation as resolved.
Show resolved Hide resolved
echo "****Done pre-commit hooks****"
Zabuzard marked this conversation as resolved.
Show resolved Hide resolved