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:
@@ -170,6 +170,24 @@ func (r *Repo) Push(branch string) error {
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// HasCommits reports whether the repository has any commit (false on
|
||||||
|
// a freshly initialised, unborn branch).
|
||||||
|
func (r *Repo) HasCommits() bool {
|
||||||
|
r.mu.Lock()
|
||||||
|
defer r.mu.Unlock()
|
||||||
|
_, err := r.run("rev-parse", "--verify", "HEAD")
|
||||||
|
return err == nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// RemoteBranchExists reports whether origin/branch is known locally
|
||||||
|
// (run Fetch first for a fresh answer).
|
||||||
|
func (r *Repo) RemoteBranchExists(branch string) bool {
|
||||||
|
r.mu.Lock()
|
||||||
|
defer r.mu.Unlock()
|
||||||
|
_, err := r.run("rev-parse", "--verify", "refs/remotes/origin/"+branch)
|
||||||
|
return err == nil
|
||||||
|
}
|
||||||
|
|
||||||
// MergeInProgress reports whether a merge has been started but not
|
// MergeInProgress reports whether a merge has been started but not
|
||||||
// yet committed or aborted.
|
// yet committed or aborted.
|
||||||
func (r *Repo) MergeInProgress() bool {
|
func (r *Repo) MergeInProgress() bool {
|
||||||
|
|||||||
@@ -186,6 +186,20 @@ func (s *Server) backgroundSync() {
|
|||||||
record(fmt.Errorf("fetch: %w", err), false)
|
record(fmt.Errorf("fetch: %w", err), false)
|
||||||
return
|
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()
|
current, err := repo.CurrentBranch()
|
||||||
if err != nil || current != gs.LiveBranch {
|
if err != nil || current != gs.LiveBranch {
|
||||||
// Someone is working on another branch; leave it alone.
|
// Someone is working on another branch; leave it alone.
|
||||||
|
|||||||
Reference in New Issue
Block a user