From fd7144e91d2149a679f106bf34f85755d7b72cb3 Mon Sep 17 00:00:00 2001 From: Drewry Pope Date: Sat, 31 Oct 2026 13:02:14 -0500 Subject: [PATCH] fix(laptop-autocommit): merge-pull + loud push failure (was: never pulls, swallows push errors) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The sweep committed tracked changes and pushed only when ahead, with push failure swallowed by || true — it NEVER pulled. Once a laptop repo diverged from origin, every push was rejected non-fast-forward invisibly, forever: the laptop hatch-personal primary silently reached 2076 commits BEHIND origin (found during the 2026-10-31 autocommit wedge repair, dezren39/hatch-personal#10, where the sandbox script had wedged the same way via rebase). Same discipline as the sandbox fix (Drew 2026-10-31: primaries merge-pull main and push back, stopping only on real conflicts): fetch, merge-pull --no-rebase --autostash when behind, push; a real merge conflict captures conflicted paths by name, aborts, restores the autostash, and exits 1 so the unit shows failed; a rejected push also exits 1. Tracked-only scope, default-branch-only, and index.lock discipline unchanged. Scratch-tested both paths: diverged-mergeable self-heals via merge commit and pushes to 0/0; same-line conflict aborts loudly with the path named. Refs dezren39/hatch-personal#10 --- nixos/home/laptop-autocommit.sh | 39 +++++++++++++++++++++++++++++---- 1 file changed, 35 insertions(+), 4 deletions(-) diff --git a/nixos/home/laptop-autocommit.sh b/nixos/home/laptop-autocommit.sh index 0356af03bc..6deb4479c0 100755 --- a/nixos/home/laptop-autocommit.sh +++ b/nixos/home/laptop-autocommit.sh @@ -2,9 +2,12 @@ # laptop-autocommit — one tracked-file sweep of one laptop repo # (Drew, 2026-10-28; developing-today/code#1723). Mirrors the # sandbox's hatch-autocommit discipline: only files git already -# tracks are committed, only on the repo's default branch, and the -# branch is pushed when ahead. Untracked files are never touched -# here — the daily laptop-untracked-review classifies those. +# tracks are committed, only on the repo's default branch, local +# commits are merge-pulled against origin and pushed back, stopping +# loudly only on real conflicts. (2026-10-31 fix: the original never +# pulled at all and swallowed push failures with || true, which +# wedged the laptop hatch-personal primary 2076 commits behind +# origin, invisibly — dezren39/hatch-personal#10.) set -u export GIT_TERMINAL_PROMPT=0 d="${1:-}" @@ -22,8 +25,36 @@ if ! git -C "$d" diff --cached --quiet; then exit 0 fi fi +# sync: fetch, MERGE-pull when behind (never rebase — divergence +# self-heals as a merge commit), then push. A real merge conflict +# aborts loudly (exit 1, so the systemd unit shows failed) with the +# conflicted paths named; a rejected push likewise fails loudly +# instead of being swallowed. Local commits are always kept. +git -C "$d" fetch -q --no-tags origin "$db" || { echo "autocommit: fetch failed in $d (deferred)"; exit 0; } +behind="$(git -C "$d" rev-list --count "HEAD..@{u}" 2>/dev/null || echo 0)" +if [ "${behind:-0}" -gt 0 ]; then + stash_before="$(git -C "$d" stash list)" + if ! git -C "$d" pull -q --no-rebase --autostash origin "$db"; then + mh="$(git -C "$d" rev-parse --git-path MERGE_HEAD)" + if [ -f "$mh" ]; then + paths="$(git -C "$d" diff --name-only --diff-filter=U | paste -sd, -)" + git -C "$d" merge --abort + [ "$(git -C "$d" stash list)" != "$stash_before" ] && git -C "$d" stash pop -q + echo "autocommit: MERGE CONFLICT syncing $d — conflicted paths: ${paths:-unknown} — aborted, local commits kept; a human must resolve (hatch-personal#10)" + exit 1 + fi + echo "autocommit: pull failed in $d (no merge in progress; deferred)" + exit 0 + fi + echo "autocommit: merge-pulled $behind commit(s) in $d" +fi ahead="$(git -C "$d" rev-list --count "@{u}..HEAD" 2>/dev/null || echo 0)" if [ "${ahead:-0}" -gt 0 ]; then - timeout 60 git -C "$d" push -q origin "$db" 2>/dev/null && echo "autocommit: pushed $ahead commit(s) in $d" || true + if timeout 60 git -C "$d" push -q origin "$db"; then + echo "autocommit: pushed $ahead commit(s) in $d" + else + echo "autocommit: PUSH FAILED in $d ($ahead commit(s) unpushed)" + exit 1 + fi fi exit 0