feat(gitsync): auto-bootstrap tom wiki från remote live-gren

Ett repo utan commits adopterar origin/<live_branch> automatiskt vid
första bakgrundssynken — färsk instans behöver ingen manuell reset.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
This commit is contained in:
2026-08-02 23:19:48 +02:00
parent e181e8e68e
commit 19cf285d80
2 changed files with 32 additions and 0 deletions

View File

@@ -186,6 +186,20 @@ func (s *Server) backgroundSync() {
record(fmt.Errorf("fetch: %w", err), false)
return
}
// Bootstrap: an empty wiki (no commits yet) adopts the remote live
// branch automatically, so a fresh instance needs no manual reset.
if !repo.HasCommits() {
if repo.RemoteBranchExists(gs.LiveBranch) {
_, err := repo.ResetToRemote(gs.LiveBranch, syncAuthor, syncEmail)
if err != nil {
record(fmt.Errorf("bootstrap från remote: %w", err), true)
} else {
log.Printf("[gitsync] empty wiki bootstrapped from origin/%s", gs.LiveBranch)
record(nil, false)
}
return
}
}
current, err := repo.CurrentBranch()
if err != nil || current != gs.LiveBranch {
// Someone is working on another branch; leave it alone.