+16
knotserver/git/fork.go
+16
knotserver/git/fork.go
···
27
return nil
28
}
29
30
+
func (g *GitRepo) Sync(branch string) error {
31
+
fetchOpts := &git.FetchOptions{
32
+
RefSpecs: []config.RefSpec{
33
+
config.RefSpec(fmt.Sprintf("+refs/heads/%s:refs/heads/%s", branch, branch)),
34
+
},
35
+
}
36
+
37
+
err := g.r.Fetch(fetchOpts)
38
+
if errors.Is(git.NoErrAlreadyUpToDate, err) {
39
+
return nil
40
+
} else if err != nil {
41
+
return fmt.Errorf("failed to fetch origin branch: %s: %w", branch, err)
42
+
}
43
+
return nil
44
+
}
45
+
46
// TrackHiddenRemoteRef tracks a hidden remote in the repository. For example,
47
// if the feature branch on the fork (forkRef) is feature-1, and the remoteRef,
48
// i.e. the branch we want to merge into, is main, this will result in a refspec: