From 413bdb7b38e578d882a72fb8e00819c0ee1b7370 Mon Sep 17 00:00:00 2001 From: jeffrey-signal Date: Tue, 9 Dec 2025 12:14:35 -0500 Subject: [PATCH] Add optional git hook to run formatter pre-push. --- .gitignore | 1 + CONTRIBUTING.md | 2 +- lefthook.yml | 15 +++++++++++++++ 3 files changed, 17 insertions(+), 1 deletion(-) create mode 100644 lefthook.yml diff --git a/.gitignore b/.gitignore index 108cb8f44c..c397d8b78f 100644 --- a/.gitignore +++ b/.gitignore @@ -32,3 +32,4 @@ maps.key /local/ kls_database.db .kotlin +lefthook-local.yml diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 85a72a099e..14c045a7a0 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -62,7 +62,7 @@ You will need to [sign our CLA](https://signal.org/cla/) before your pull reques ### 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. -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 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. diff --git a/lefthook.yml b/lefthook.yml new file mode 100644 index 0000000000..86930d34b9 --- /dev/null +++ b/lefthook.yml @@ -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."