Skip to content

Commit f4cc384

Browse files
added post commit hook to run spotless command (#936)
## Description 1. Add a script to run spotless post commit 2. Since githooks are not tracked, moved them to a script folder with symlink to the actual git hook ## Testing <img width="913" height="782" alt="Screenshot 2025-08-12 at 2 47 20 PM" src="https://github.com/user-attachments/assets/19c5055b-022e-4489-baf6-a12812f9d664" /> ## Additional Notes to the Reviewer 1. Need to update README if the approach is finalised NO_CHANGELOG=true --------- Signed-off-by: Nikhil Suri <[email protected]>
1 parent e5ce12c commit f4cc384

File tree

3 files changed

+31
-0
lines changed

3 files changed

+31
-0
lines changed

CONTRIBUTING.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,14 @@ Additional git and GitHub resources:
9191
We recommend using IntelliJ to develop the Databricks JDBC Driver. You can download the community edition [here](https://www.jetbrains.com/idea/download/).
9292
Once you have IntelliJ installed, open the Databricks JDBC Driver project by selecting `File -> Open` and selecting the
9393
`databricks-jdbc` folder. Ensure that you have the Maven plugin loaded.
94+
- Git Hooks - To ensure commit quality and enforce project policies (such as with our new post-commit hook), you must install the git hooks contained in scripts/githooks.
95+
Please run the following command after cloning the repository:
96+
```bash
97+
chmod +x ./scripts/setup-git-hooks.sh
98+
````
99+
``` bash
100+
./scripts/setup-git-hooks.sh
101+
```
94102

95103
## Debugging
96104

scripts/githooks/post-commit

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
#!/bin/sh
2+
3+
# Run Maven spotless to auto-format (if needed)
4+
mvn spotless:apply
5+
6+
# Check if there are any changes after formatting
7+
if ! git diff --quiet; then
8+
echo
9+
echo "========================================================================"
10+
echo "✨ Spotless applied formatting changes after your commit."
11+
echo "There are uncommitted changes in your working directory."
12+
echo "Please 'git add' and 'git commit' these to include formatting changes."
13+
echo "========================================================================"
14+
echo
15+
# Optional: show the changed files
16+
git status --short
17+
else
18+
echo
19+
echo "✓ Spotless checked: No further formatting changes needed after commit."
20+
echo
21+
fi

scripts/setup-git-hooks.sh

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
ln -sf ../../scripts/githooks/post-commit .git/hooks/post-commit
2+
chmod +x .git/hooks/post-commit

0 commit comments

Comments
 (0)