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