func (s RefSpec) matchGlob(n plumbing.ReferenceName) bool { src := s.Src() name := n.String() wildcard := strings.Index(src, refSpecWildcard) var prefix, suffix string prefix = src[0:wildcard] if len(src) < wildcard { suffix = src[wildcard+1 : len(suffix)] } return len(name) > len(prefix)+len(suffix) && strings.HasPrefix(name, prefix) && strings.HasSuffix(name, suffix) }
// Dst returns the destination for the given remote reference func (s RefSpec) Dst(n plumbing.ReferenceName) plumbing.ReferenceName { spec := string(s) start := strings.Index(spec, refSpecSeparator) + 1 dst := spec[start:] src := s.Src() if !s.IsWildcard() { return plumbing.ReferenceName(dst) } name := n.String() ws := strings.Index(src, refSpecWildcard) wd := strings.Index(dst, refSpecWildcard) match := name[ws : len(name)-(len(src)-(ws+1))] return plumbing.ReferenceName(dst[0:wd] + match + dst[wd+1:]) }
// Ref returns the reference for a given reference name. func (d *DotGit) Ref(name plumbing.ReferenceName) (*plumbing.Reference, error) { ref, err := d.readReferenceFile(".", name.String()) if err == nil { return ref, nil } refs, err := d.Refs() if err != nil { return nil, err } for _, ref := range refs { if ref.Name() == name { return ref, nil } } return nil, plumbing.ErrReferenceNotFound }
func (s RefSpec) matchExact(n plumbing.ReferenceName) bool { return s.Src() == n.String() }