Skip to content
Closed
Show file tree
Hide file tree
Changes from all 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
7 changes: 7 additions & 0 deletions .githooks/pre-commit
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure that running git diff --name-only | xargs -r git add is quite the right thing. It changes the behavior of git commit to stage all modified files, not just the ones that the user had staged. Second, the xargs invocation will choke on any files with whitespace in their name.

Original file line number Diff line number Diff line change
@@ -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
6 changes: 4 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)

Expand Down
7 changes: 7 additions & 0 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
13 changes: 3 additions & 10 deletions doc/CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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
Expand Down
Loading