diff --git a/.githooks/pre-commit b/.githooks/pre-commit new file mode 100644 index 0000000..112ab8d --- /dev/null +++ b/.githooks/pre-commit @@ -0,0 +1,7 @@ +#!/bin/sh +./gradlew spotlessApply --quiet +if [ $? -ne 0 ]; then + echo "spotlessApply failed — commit aborted" + exit 1 +fi +git diff --name-only | xargs -r git add \ No newline at end of file diff --git a/README.md b/README.md index f225f91..8e919a6 100644 --- a/README.md +++ b/README.md @@ -72,7 +72,9 @@ Use the Gradle wrapper — no separate Gradle installation needed. ## Code Formatting -This project uses [Spotless](https://github.com/diffplug/spotless) with Google Java Format. Formatting is applied automatically on every build. +This project uses [Spotless](https://github.com/diffplug/spotless) with Google Java Format. Formatting is applied automatically on every build and on every commit (via `.githooks/pre-commit`). + +The hook is installed automatically the first time you run `./gradlew build`. **Apply formatting manually:** ```bash @@ -142,7 +144,7 @@ This project is licensed under the [BSD 3-Clause License](LICENSE). See individu ### Triple Helix Robotics (FRC Team 2363) -The robot-specific subsystems and supporting utilities are original work by Triple Helix Robotics, copyright 2025. +The robot-specific subsystems and supporting utilities are original work by Triple Helix Robotics, copyright 2025-2026. ### AdvantageKit — Littleton Robotics (FRC 6328) diff --git a/build.gradle b/build.gradle index bf72faa..bc3248d 100644 --- a/build.gradle +++ b/build.gradle @@ -203,6 +203,13 @@ task(eventDeploy) { } createVersionFile.dependsOn(eventDeploy) +// Install git hooks on first build +task installHooks(type: Exec) { + onlyIf { !System.getenv("CI") } + commandLine "git", "config", "core.hooksPath", ".githooks" +} +project.compileJava.dependsOn(installHooks) + // Spotless formatting project.compileJava.dependsOn(spotlessApply) spotless { diff --git a/doc/CONTRIBUTING.md b/doc/CONTRIBUTING.md index 22268a2..ed81b3c 100644 --- a/doc/CONTRIBUTING.md +++ b/doc/CONTRIBUTING.md @@ -166,20 +166,13 @@ If `main` has changes that overlap with your branch, Git will flag conflicts. Do ### Final check before opening a PR -Run the full build and formatting check one more time before pushing. Use `./gradlew` on Mac/Linux or Git Bash; use `gradlew` in Windows Command Prompt: +Run the full build one more time before pushing. Use `./gradlew` on Mac/Linux or Git Bash; use `gradlew` in Windows Command Prompt: ```bash ./gradlew build -./gradlew spotlessCheck ``` -If `spotlessCheck` fails, it means there are formatting issues. Apply the formatter automatically: - -```bash -./gradlew spotlessApply -``` - -Review the diff, then stage and commit the formatting changes before pushing. CI will run `spotlessCheck` automatically on your PR and will fail if formatting is not clean. +Formatting is applied automatically on every commit by the pre-commit hook (installed on first build), so it should already be clean. CI will run `spotlessCheck` on your PR and will fail if formatting is not clean — if that happens, run `./gradlew spotlessApply`, commit, and push. ### Open a pull request @@ -207,7 +200,7 @@ Once approved and CI is green, a mentor or senior programmer will merge the PR. ### Formatting -This project uses [Spotless](https://github.com/diffplug/spotless) with Google Java Format to keep code style consistent across the whole codebase. Formatting is applied automatically every time you run `./gradlew build`, so in most cases you do not need to think about it. If you ever want to apply it manually without building: +This project uses [Spotless](https://github.com/diffplug/spotless) with Google Java Format to keep code style consistent across the whole codebase. Formatting is applied automatically on every build and on every commit via a pre-commit hook in `.githooks/`. The hook is installed automatically the first time you run `./gradlew build`, so in most cases you do not need to think about it. If you ever want to apply it manually: ```bash ./gradlew spotlessApply