Add optional git hook to run formatter pre-push.

This commit is contained in:
jeffrey-signal
2025-12-09 12:14:35 -05:00
committed by Michelle Tang
parent 5e81f9c720
commit 413bdb7b38
3 changed files with 17 additions and 1 deletions

1
.gitignore vendored
View File

@@ -32,3 +32,4 @@ maps.key
/local/ /local/
kls_database.db kls_database.db
.kotlin .kotlin
lefthook-local.yml

View File

@@ -62,7 +62,7 @@ You will need to [sign our CLA](https://signal.org/cla/) before your pull reques
### Follow the Code Style Guidelines ### Follow the Code Style Guidelines
Ensure that your code adheres to the [Code Style Guidelines](https://github.com/signalapp/Signal-Android/wiki/Code-Style-Guidelines) before submitting a pull request. Ensure that your code adheres to the [Code Style Guidelines](https://github.com/signalapp/Signal-Android/wiki/Code-Style-Guidelines) before submitting a pull request.
You can run `./gradlew format` to automatically check conformance with some of these guidelines. You can run `./gradlew format` to automatically format your code. See `lefthook.yml` for instructions on how to run this as a git hook.
### Submit finished and well-tested pull requests ### Submit finished and well-tested pull requests
Please do not submit pull requests that are still a work in progress. Pull requests should be thoroughly tested and ready to merge before they are submitted. Please do not submit pull requests that are still a work in progress. Pull requests should be thoroughly tested and ready to merge before they are submitted.

15
lefthook.yml Normal file
View File

@@ -0,0 +1,15 @@
# Lefthook git hooks configuration
#
# ========== SETUP ==========
# 1. Install lefthook: https://lefthook.dev/installation/
# 2. Enable hooks: lefthook install
#
# ========== CUSTOMIZATION ==========
# Create lefthook-local.yml (gitignored) to override settings locally.
# https://lefthook.dev/examples/lefthook-local.html
pre-push:
commands:
format:
run: ./gradlew format --quiet && test -z "$(git status --porcelain)"
fail_text: "Formatting changes detected. Please commit them and push again."