A Ref Only One Machine Writes

Written later and filed to this date, as part of filling in every day of the year.

On a Saturday in June the small always-on box became the host and the laptop became a remote control. Every repository in the workspace now had two working copies on two disks: agents committing on one, me committing on the other, and a commit on either side existed on exactly one machine until something moved it. The first code written that morning was repo-sync.

It has two layers, and the order matters.

The first is redundancy, and it is unconditional. Every fifteen minutes, each machine force-pushes its current head to a ref on the remote named for that machine, _sync/<host>. The ref has exactly one writer, so the force-push never conflicts with anything, and the remote always holds an exact mirror of each machine’s state. Lose a machine and its last quarter hour of commits is the most you lose; fetch its ref and you have the rest.

The second is convergence, and it is cautious. On the real branch, the timer fast-forwards when it is only behind, pushes when it is only ahead, and rebases then pushes when the two have diverged. A rebase that conflicts is aborted and flagged for a human. The timer never resolves a conflict itself, and it does not need to, because the work on both sides is already safe under each machine’s own name.

The list of what it refuses is as long as the list of what it does. It never force-pushes a real branch. It never commits a dirty tree; an uncommitted change is reported, not swept up. It skips any repository with no remote. And it hard-excludes the public site, because pushing even a side branch of that one builds a preview on the open web, and that push stays a deliberate act by a person.

The obvious design is a single branch that both machines push to, and that design has a conflict in it by the first afternoon both machines commit. Splitting “is my work safe” from “do the copies agree” lets the first answer be always yes and the second be allowed to wait.

repo-sync: a timer on each machine that pushes every private repository to a ref only that machine writes, every fifteen minutes, so that a commit is a backup within a quarter of an hour, and a public push is never one of them.


← all writing