From f2d25d3103a56ee91a476ad9ad79b217d7ce9d95 Mon Sep 17 00:00:00 2001 From: BrookJeynes Date: Tue, 13 May 2025 01:08:55 +1000 Subject: [PATCH] knotserver: fork: add function to sync fork --- knotserver/git/fork.go | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/knotserver/git/fork.go b/knotserver/git/fork.go index b74be539..a35b5134 100644 --- a/knotserver/git/fork.go +++ b/knotserver/git/fork.go @@ -27,6 +27,22 @@ func Fork(repoPath, source string) error { return nil } +func (g *GitRepo) Sync(branch string) error { + fetchOpts := &git.FetchOptions{ + RefSpecs: []config.RefSpec{ + config.RefSpec(fmt.Sprintf("+refs/heads/%s:refs/heads/%s", branch, branch)), + }, + } + + err := g.r.Fetch(fetchOpts) + if errors.Is(git.NoErrAlreadyUpToDate, err) { + return nil + } else if err != nil { + return fmt.Errorf("failed to fetch origin branch: %s: %w", branch, err) + } + return nil +} + // TrackHiddenRemoteRef tracks a hidden remote in the repository. For example, // if the feature branch on the fork (forkRef) is feature-1, and the remoteRef, // i.e. the branch we want to merge into, is main, this will result in a refspec: -- 2.51.2