Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
39 changes: 35 additions & 4 deletions nixos/home/laptop-autocommit.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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:-}"
Expand All @@ -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
Comment on lines +38 to +39

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Badge Resolve MERGE_HEAD to an absolute path before testing it

When invoked outside the target repository, as in laptop-autocommit.nix's service without a repository working directory, this command returns .git/MERGE_HEAD, but the shell tests that path relative to its own directory. A real merge conflict therefore skips the abort and exits successfully, leaving unresolved files behind. I reproduced this with two diverged clones: the next sweep's git add -u staged the conflict markers, committed them as a merge, and pushed the corrupted file. Request --path-format=absolute before --git-path; the Git documentation specifies that this makes the returned paths “absolute and canonical.”

Useful? React with 👍 / 👎.

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