forked from bchanot/claude
job4: fix memory-commit fail-loud
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.
This commit is contained in:
+14
-1
@@ -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
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user