From f2e9ce04d4306f1c41b8b615fec53661e9ccc77b Mon Sep 17 00:00:00 2001 From: Kevin Veen-Birkenbach Date: Tue, 28 Jul 2026 17:01:11 +0200 Subject: [PATCH] fix(git-hooks): run the merge-signed gate on prepare-commit-msg git writes MERGE_HEAD only after the pre-merge-commit hook returns, so the gate never found it and aborted every non-fast-forward merge with "No merge in progress"; git then wrote the merge state via abort_commit(), leaving a half-finished merge that git status reported as "still merging". The gate had therefore never verified a single signature. git also skips pre-merge-commit entirely once a merge conflicts, so the conflict-resolution commit was unguarded as well. prepare-commit-msg fires with MERGE_HEAD present on both paths and no-ops on ordinary commits. Verified in a scratch repo with a real pre-commit install: ordinary commit passes silently, clean automerge and conflict-resolution commit both block an unsigned incoming commit, and the extra stash/restore cycle round-trips unstaged changes byte-identically. pre_commit install never removes hook types dropped from the config, so the install script now also uninstalls the stale pre-merge-commit hook. --- .pre-commit-config.yaml | 6 +++--- Makefile | 2 +- scripts/git/assert/merge_signed.sh | 9 ++++----- scripts/install/pre-commit.sh | 1 + 4 files changed, 9 insertions(+), 9 deletions(-) diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 6b3f7e3bb1..abbfa70575 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -1,7 +1,7 @@ --- default_install_hook_types: - pre-commit - - pre-merge-commit + - prepare-commit-msg - pre-push - post-checkout @@ -16,13 +16,13 @@ repos: stages: - pre-commit - id: make-test-merge-signed - name: Run make test-merge-signed (pre-merge-commit gate) + name: Run make test-merge-signed (merge gate) entry: make test-merge-signed language: system pass_filenames: false always_run: true stages: - - pre-merge-commit + - prepare-commit-msg - id: make-lint name: Run make lint (pre-push gate) entry: make lint diff --git a/Makefile b/Makefile index e42871cec3..d83ca29877 100644 --- a/Makefile +++ b/Makefile @@ -745,7 +745,7 @@ test-main-merged: @bash scripts/git/assert/main_merged.sh .PHONY: test-merge-signed -# Verify every commit an in-progress merge brings in (HEAD..MERGE_HEAD) is signed (pre-merge-commit gate). +# Verify every commit an in-progress merge brings in (HEAD..MERGE_HEAD) is signed (prepare-commit-msg gate). test-merge-signed: @bash scripts/git/assert/merge_signed.sh diff --git a/scripts/git/assert/merge_signed.sh b/scripts/git/assert/merge_signed.sh index fdefc39027..9abfb1cbd9 100755 --- a/scripts/git/assert/merge_signed.sh +++ b/scripts/git/assert/merge_signed.sh @@ -1,14 +1,13 @@ #!/usr/bin/env bash set -euo pipefail -# Pre-merge-commit gate: every commit the merge brings in (HEAD..MERGE_HEAD) -# must carry a signature. `git log %G?` yields N for unsigned; any other -# status counts as signed, matching the test-signed HEAD gate. +# Merge gate: every commit the merge brings in (HEAD..MERGE_HEAD) must carry +# a signature. `git log %G?` yields N for unsigned; any other status counts +# as signed, matching the test-signed HEAD gate. git_dir="$(git rev-parse --git-dir)" if [ ! -f "${git_dir}/MERGE_HEAD" ]; then - echo "❌ No merge in progress (MERGE_HEAD missing); this gate runs during git merge." >&2 - exit 1 + exit 0 fi unsigned="$(git log --pretty='%H %G? %s' HEAD..MERGE_HEAD | awk '$2 == "N"')" diff --git a/scripts/install/pre-commit.sh b/scripts/install/pre-commit.sh index d1033b36b7..a720487d1a 100755 --- a/scripts/install/pre-commit.sh +++ b/scripts/install/pre-commit.sh @@ -5,3 +5,4 @@ set -euo pipefail echo "🔗 Installing pre-commit hooks" "${PYTHON}" -m pre_commit install +"${PYTHON}" -m pre_commit uninstall -t pre-merge-commit