func (r *Repository) updateRemoteConfig( remote *Remote, o *CloneOptions, c *config.RemoteConfig, ) error { if !o.SingleBranch { return nil } head, err := storer.ResolveReference(remote.Info().Refs, o.ReferenceName) if err != nil { return err } c.Fetch = []config.RefSpec{ config.RefSpec(fmt.Sprintf(refspecSingleBranch, head.Name().Short(), c.Name)), } cfg, err := r.s.Config() if err != nil { return err } cfg.Remotes[c.Name] = c return r.s.SetConfig(cfg) }
// CreateRemote creates a new remote func (r *Repository) CreateRemote(c *config.RemoteConfig) (*Remote, error) { if err := c.Validate(); err != nil { return nil, err } remote := newRemote(r.s, c) cfg, err := r.s.Config() if err != nil { return nil, err } if _, ok := cfg.Remotes[c.Name]; ok { return nil, ErrRemoteExists } cfg.Remotes[c.Name] = c return remote, r.s.SetConfig(cfg) }