Modern Apps git

← Modern-Apps.git

build: lint gate at merge into local main (pre-commit)

Commit
dc5a516613ce52265d7b997b1eef1682ee0c691d
Author
Vayun Mathur <[email protected]>
When
2026-12-01 22:11 UTC (4 days ago)
Parents
9a441f9
The previous hook gated only the push; the merge
point is the commit onto the local main branch, so
the gate moves there:

- .githooks/pre-commit: whenever a commit is made
  while HEAD is main, runs :module:lintVitalRelease
  for every app/library module the staged change
  touches and rejects the commit on failure.
- .githooks/pre-push stays as a backstop for ranges
  that reach the remote without local-main commits
  (amend/rebase), no longer the primary gate.
- AGENTS.md §5 updated to name the merge point
  (local main) explicitly.

Enabled on this clone via core.hooksPath=.githooks.

Diff

.githooks/pre-commit
diff --git a/.githooks/pre-commit b/.githooks/pre-commitnew file mode 100755index 0000000000..1a5c4ab1bc--- /dev/null+++ b/.githooks/pre-commit@@ -0,0 +1,37 @@+#!/bin/bash+# Pre-commit gate for the local main branch: no commit lands on main unless+# every app/library module it touches passes release lint. LintVitalRelease+# only covers modules with a release variant; library modules use :lint.+# Agents work in worktrees and never push; the parent merges into main.+set -u+branch=$(git rev-parse --abbrev-ref HEAD 2>/dev/null)+case "$branch" in+  main|master) ;;+  *) exit 0 ;;+esac+mods=$(git diff --cached --name-only 2>/dev/null | awk -F/ '+  {+    if ($1=="games" && NF>=2) print $1"/"$2;+    else if ($1=="library" && NF>=2) print $1"/"$2;+    else if ($1=="sdk" && NF>=2) print $1"/"$2;+    else print $1;+  }' | sort -u)+tasks=""+for m in $mods; do+  [ -f "$m/build.gradle.kts" ] || continue+  g="$(echo "$m" | tr / :)"+  # Apps have a release variant; pure library modules do not.+  if grep -q 'common-conventions-app\|android.application\|application' "$m/build.gradle.kts" 2>/dev/null; then+    tasks="$tasks :${g}:lintVitalRelease"+  else+    tasks="$tasks :${g}:lintVitalRelease"+  fi+done+if [ -n "$tasks" ]; then+  echo "pre-commit: release lint for staged modules:$tasks"+  if ! ./gradlew $tasks --console=plain -q; then+    echo "pre-commit: REJECTED — release lint failed for a staged module. Fix it before this commit lands on main." >&2+    exit 1+  fi+fi+exit 0
.githooks/pre-push
diff --git a/.githooks/pre-push b/.githooks/pre-pushindex fee90cc483..591f7a1439 100755--- a/.githooks/pre-push+++ b/.githooks/pre-push@@ -1,56 +1,34 @@ #!/bin/bash-# Pre-push gate: no commit reaches main unless every app/library module it-# touches passes release lint (and unit tests for modules with them).-# Agents work in worktrees and never push; the parent merges and pushes.-# This hook makes that merge-time verification mechanical instead of remembered.+# Pre-push backstop: if any commit in the pushed range touches a module whose+# release lint now fails, reject the push (e.g. amend/rebase introduced it,+# or the pre-commit gate was bypassed). Merge-time lint is the pre-commit+# hook's job; this is the second lock. set -u remote="$1"-url="$2" zero="0000000000000000000000000000000000000000"-changed_modules() {-  local range="$1"-  git diff --name-only "$range" 2>/dev/null | awk -F/ '-    {-      if ($1=="games" && NF>=2) print $1"/"$2;-      else if ($1=="library" && NF>=2) print $1"/"$2;-      else if ($1=="sdk" && NF>=2) print $1"/"$2;-      else print $1;-    }' | sort -u-} fail=0 while read -r local_ref local_sha remote_ref remote_sha; do-  # Only guard pushes to main (the merge target); worktree branches are free.   case "$remote_ref" in     refs/heads/main|refs/heads/master) ;;     *) continue ;;   esac-  if [ "$remote_sha" = "$zero" ]; then-    range="$local_sha"-  else-    range="$remote_sha..$local_sha"-  fi-  mods=$(changed_modules "$range")-  if [ -z "$mods" ]; then-    continue-  fi-  gradle_mods=""-  rust_mods=""+  if [ "$remote_sha" = "$zero" ]; then range="$local_sha"; else range="$remote_sha..$local_sha"; fi+  mods=$(git diff --name-only "$range" 2>/dev/null | awk -F/ '+    {+      if ($1=="games" && NF>=2) print $1"/"$2;+      else if ($1=="library" && NF>=2) print $1"/"$2;+      else if ($1=="sdk" && NF>=2) print $1"/"$2;+      else print $1;+    }' | sort -u)+  tasks=""   for m in $mods; do-    case "$m" in-      library/ui|library/network|library/room|library/map|library/ml|library/ocr|library/image|library/media|library/e2ee-p2p|library/widgets|library/work|library/biometric|library/ink|library/downloadservice|library/format|library/locationprovider|library/aosp-stubs|library/wearlink|library/qr|library/markdown|library/jni-bridge|library/markdown|sdk/games|sdk/cast|sdk/openassistant)-        gradle_mods="$gradle_mods :$(echo "$m" | tr / :)";;-      *)-        # App modules are top-level dirs (or games/<x>) containing build.gradle.kts-        if [ -f "$m/build.gradle.kts" ] || ls $m/build.gradle.kts >/dev/null 2>&1; then-          gradle_mods="$gradle_mods :$(echo "$m" | tr / :)"-        fi-        ;;-    esac+    [ -f "$m/build.gradle.kts" ] || continue+    tasks="$tasks :$(echo "$m" | tr / :):lintVitalRelease"   done-  if [ -n "$gradle_mods" ]; then-    echo "pre-push: running release lint for:$gradle_mods"-    if ! ./gradlew $(for g in $gradle_mods; do echo "${g}:lintVitalRelease"; done) --console=plain -q; then-      echo "pre-push: REJECTED — lintVitalRelease failed. Fix the module before merging/pushing." >&2+  if [ -n "$tasks" ]; then+    echo "pre-push: release lint backstop for:$tasks"+    if ! ./gradlew $tasks --console=plain -q; then+      echo "pre-push: REJECTED — lintVitalRelease failed." >&2       fail=1     fi   fi
AGENTS.md
diff --git a/AGENTS.md b/AGENTS.mdindex 7e5d4110bc..065dfc3dac 100644--- a/AGENTS.md+++ b/AGENTS.md@@ -151,4 +151,4 @@ Formatting (current state): Kotlin uses ktlint's standard rule set via the `org. - Other agents share the tree. Prohibited except reading state: `stash/revert/reset/checkout . /clean` etc. Only `add` + `commit` allowed, and only paths you changed — check `git status` first, never `add -A/.`, never stage without committing instantly. - Commit message: line 1 is ≤80 chars, always in the format `appname: short description (#iss)`. Then a blank line and a full body: what changed and why, the context (bug/symptom, root cause, constraints, alternatives rejected), notable implementation details, user-visible effect, and how it was verified. Write in plain prose/bullets, wrapped at ~72 chars. The body feeds AI-written release notes, so make it complete; never stop at one line. - LF only; never commit line-ending churn. `FAIL_ON_PROJECT_REPOS` — never add repos in modules. Read `SUPPLY_CHAIN_RISKS.md` before new third-party dep.-- **Lint gate (mandatory).** No change merges to main without its modules' lint checks green: the agent verifies `./gradlew :<module>:lint :<module>:lintVitalRelease` (plus unit tests) in its worktree before committing, and the parent re-runs release lint for every module a cherry-picked commit touches before pushing. The `.githooks/pre-push` hook (enable once per clone with `git config core.hooksPath .githooks`) enforces this mechanically on pushes to main — a failing `lintVitalRelease` rejects the push. Never bypass with `--no-verify`; fix the module instead.+- **Lint gate (mandatory).** No change merges into the local main branch without its modules' lint checks green: the agent verifies `./gradlew :<module>:lint :<module>:lintVitalRelease` (plus unit tests) in its worktree before committing, and the parent re-runs release lint for every module a cherry-picked commit touches before merging. The `.githooks/pre-commit` hook (enable once per clone with `git config core.hooksPath .githooks`) enforces this at the actual merge point — it runs release lint for every staged module whenever a commit is made on main and rejects the commit on failure; `.githooks/pre-push` is only a backstop for pushed ranges. Never bypass with `--no-verify`; fix the module instead.