From aae8cd68f6dcff100958dda0ed509ce3e655e78b Mon Sep 17 00:00:00 2001 From: Bastien Chanot Date: Mon, 6 Jul 2026 19:34:31 +0200 Subject: [PATCH] job4: fix memory-commit fail-loud MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Ports doc-commit.sh:123-138's fail-loud pattern verbatim-adapted. `commit_memory` now checks `git commit`'s own exit status: on rejection (pre-commit hook, protected branch, signing failure, …) it returns 5 (mirrors doc-commit's rc 5 — memory-commit's 0/2/3 were already taken) with a loud stderr message and NOTHING on stdout, instead of falling through to `git rev-parse --short HEAD` and silently reporting the previous (stale) commit as if it were new. Closes J4-04 (UNTESTABLE, consequence CRITICAL). Previous commit ("test memory-commit masked failure (red)") proved the bug live: rc=0, stale hash leaked on stdout, on the CURRENT code. This commit turns that same T8 green: rc=5, empty stdout, HEAD unmoved. GREEN: full `make test` exit 0 — 90(gitflow)/16(deterministic, T8 included)/32(doc-commit)/23(doc-shape)/25(reconcile)/5(release) + 24/4/13/20 (*.test.sh), shellcheck clean. --- lib/memory-commit.sh | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/lib/memory-commit.sh b/lib/memory-commit.sh index 52b7065..e09aae4 100755 --- a/lib/memory-commit.sh +++ b/lib/memory-commit.sh @@ -83,7 +83,20 @@ commit_memory() { fi # Contract: diagnostics go to stderr; on success ONLY the memory-commit short # hash goes to stdout, so a caller can do `mem_hash=$(... commit "msg")`. - git commit -q -m "$msg" -- "${changed[@]}" + # FAIL-LOUD on the commit itself. With `set -uo pipefail` (no -e), a rejected + # commit (pre-commit hook on a protected branch, signing failure, …) would NOT + # abort: the line below would falsely claim "committed" and rev-parse would + # emit the PREVIOUS HEAD's hash with exit 0 — a silent masked failure. Reject + # → loud, NO hash on stdout, exit 5 (mirrors doc-commit.sh's rc 5). + if ! git commit -q -m "$msg" -- "${changed[@]}"; then + { + echo "memory-commit: COMMIT REJECTED — git commit exited non-zero" \ + "(pre-commit hook? protected branch? signing?)." + echo "memory-commit: NOTHING committed, working tree left as-is," \ + "NO hash emitted — investigate before retry." + } >&2 + return 5 + fi git rev-parse --short HEAD }