Skip to content

setup(git): pull the config repo every 5 minutes, so a machine follows main - #380

Open
landsman wants to merge 6 commits into
mainfrom
setup/auto-pull
Open

landsman wants to merge 6 commits into
mainfrom
setup/auto-pull

Conversation

@landsman

@landsman landsman commented Nov 30, 2026 •

Copy link
Copy Markdown
Owner

Every 5 minutes, bin/git/auto-pull.sh fetches each repo in bin/git/auto-pull.conf and fast-forwards it to its upstream. make git-auto-pull says whether it runs and, on a y, links the job in (a LaunchAgent on macOS, a systemd user timer on Linux) or removes it, a reboot included. It turns on only from ~/projects/landsman/config, the path the job runs. The job files sit in bin/git/, not in a stow package: launchd loads every plist in ~/Library/LaunchAgents at login, so a stowed one would run on a new Mac before anyone asked for it.

When the remote did not move, nothing is touched. When it did, local changes the update does not reach stay in place. A change in the way is saved as a stash commit under refs/auto-pull/ and then reset, never on the stash stack, which every worktree shares. Recover one with git for-each-ref refs/auto-pull, then git stash apply <ref>.

Git's own fast-forward decides what an untracked file blocks. A hand-written check before it missed a rename onto an untracked file, an accented file name, and a file where the remote adds a folder; each is now a case in auto-pull.test.sh. When the merge refuses, the saved changes go back and the run fails. Skipped as before: a branch other than the remote's default, unpushed commits, a merge, rebase, cherry-pick or revert half done.

A failure is reported as one: a path that is no repo or sits inside one, a missing upstream, a locked index. pull runs on the left of ||, where bash ignores set -e, so each git call checks its own result.

Nothing waits. SSH gets BatchMode and keepalive timeouts, added to a repo's own core.sshCommand; HTTPS gets a low-speed limit and no credential prompt; the systemd unit has a start timeout. A user service on Linux does not always inherit SSH_AUTH_SOCK, so without one the script uses the openssh or desktop keyring agent under $XDG_RUNTIME_DIR.

This repo is public, so a client's checkout goes in an untracked ~/.config/auto-pull.conf. Written for the bash 3.2 that launchd runs on macOS, which is what the test runs it with.

Not tried yet: on and off against a real launchd and systemd, which needs this merged.

@landsman landsman changed the title setup(git): pull the config repo every 5 minutes, so a machine never runs an old main setup(git): pull the config repo every 5 minutes, so a machine follows main Nov 30, 2026
@landsman

landsman commented Dec 4, 2026

Copy link
Copy Markdown
Owner Author

@claude review it

@claude

claude Bot commented Dec 4, 2026 •

Copy link
Copy Markdown

Claude finished @landsman's task in 35s —— View job


Review of #380: auto-pull

  • Read the diff (Makefile, README, docs, bin/git/*)
  • Ran bin/git/auto-pull.test.sh locally with /bin/bash. Every case passes and there are no FAIL lines. make bin-test already picks it up through git ls-files '*.test.sh'.
  • Posted the review

Verdict

This looks good to merge. I found no correctness bugs.

  • Save order: the sequence is stash create, then update-ref, then reset --hard, then merge --ff-only. The change is saved under a ref before anything destructive runs, and it is restored if the merge refuses.
  • First merge: it tries merge --ff-only before any stash, so a repo whose remote did not touch the local changes is never reset.
  • Failure reporting: each git call checks its own result because pull runs on the left of ||. The tests cover the cases where a failure could pass as a skip.

Things worth a look (none blocking)

  1. The checkout path is hard-coded in three places. auto-pull.service has ExecStart=%h/projects/landsman/config/..., and local.auto-pull.plist has $HOME/projects/landsman/config/.... The script itself uses $here, and on links the unit and plist files from $here. A checkout anywhere else gets a job that runs a missing script, or a different copy than the one linked. on could check that $here matches the path in the job files and fail loudly if it doesn't. A comment saying "the checkout must live here" would also do.
  2. A refs/auto-pull ref name has one-second resolution (bin/git/auto-pull.sh:75). update-ref overwrites silently, so two saves in the same second would lose the first. Two runs in one second is very unlikely, but appending $$ or the short sha to the name costs nothing.
  3. Saved refs are never pruned. A repo with a constantly dirty file in the way gets a new ref on every remote move. That is cheap, but a line in the README about git update-ref -d would help.
  4. Untracked files are not saved. This is intended, since git's own merge decides what they block and they are never reset. The header comment is clear about it.
  5. Stale origin/HEAD. If the remote's default branch is renamed, refs/remotes/origin/HEAD stays stale until someone runs git remote set-head origin -a. The job would then keep following the old name and report "no origin/old" on every run. The failure is loud, so this is only a note.
  6. README nit. The new bullet uses : after the link, but the neighbouring entries use —.
  7. Known and acknowledged: the log growth (a skip writes a line every 5 minutes) is documented as a ponytail: in the plist.

Not verified

I did not exercise on and off against real launchd or systemd. The PR body says the same. On Linux, systemctl --user link needs absolute paths, and $here is absolute, so that looks fine.
· branch setup/auto-pull

@landsman

landsman commented Dec 4, 2026

Copy link
Copy Markdown
Owner Author

Thanks. Per point:

  1. Fixed in b9265f1: on refuses unless it runs from ~/projects/landsman/config, the path the plist and the service run, so a worktree or a second clone cannot link a job that runs another copy. New check in auto-pull.test.sh, red with the guard disabled.
  2. Fixed in b9265f1: the ref name ends with the saved commit's short sha, so two saves in one second no longer share a name.
  3. The header now says how to drop one (git update-ref -d <ref>). No pruning: a saved change is somebody's work, so deleting it stays a person's call.
  4. No change, as you say.
  5. No change: it fails loudly on every run and git remote set-head origin -a fixes it.
  6. No change: the long dash is kept out of this repo on purpose; the neighbours predate that.
  7. No change, documented.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant