Skip to content

Commit fa15b8f

Browse files
committed
Add pre-commit hook for spotlessApply
1 parent b38edba commit fa15b8f

2 files changed

Lines changed: 17 additions & 0 deletions

File tree

build.gradle

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -322,3 +322,9 @@ spotless {
322322
removeUnusedImports()
323323
}
324324
}
325+
326+
tasks.register('updateGitHooks', Copy) {
327+
from './scripts/pre-commit'
328+
into './.git/hooks'
329+
}
330+
compileJava.dependsOn updateGitHooks

scripts/pre-commit

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
#!/bin/sh
2+
stagedFiles=$(git diff --staged --name-only)
3+
4+
echo "Formatting code..."
5+
./gradlew spotlessApply
6+
7+
for file in $stagedFiles; do
8+
if test -f "$file"; then
9+
git add $file
10+
fi
11+
done

0 commit comments

Comments
 (0)