knowledge: reset local tree before pulling to avoid ff-only wedge

This commit is contained in:
damocles 2026-08-24 13:09:31 +02:00 committed by mara
commit c93dcff074

View file

@ -254,6 +254,21 @@ pub async fn pull(coord: &Coordinator) -> Result<()> {
.args(["-C", LOCAL_DIR, "remote", "set-url", "origin", &plain])
.output()
.await;
// Discard any local modifications before pulling. Nothing in this
// codebase writes to `LOCAL_DIR` after the initial clone (`seed_readme`
// runs once, at creation, before any pull) — this working tree exists
// to mirror `origin/main`, not to be edited in place. A tracked file
// left dirty by any other means (a stray manual edit on the host, an
// interrupted prior operation) would otherwise abort the `--ff-only`
// merge below with "local changes would be overwritten", wedging
// every future pull the same way until someone notices and resets it
// by hand. Best-effort: a reset failure surfaces through the pull's
// own error below rather than needing its own branch here.
let _ = crate::lifecycle::git_command()
.args(["-C", LOCAL_DIR, "reset", "--hard", "HEAD"])
.output()
.await;
let before = head_sha().await;
// The repo is public (`ensure_knowledge_repo` makes it so), so an
// unauthenticated pull is enough — but authenticate when a token is around,