示例#1
0
func (r ReferenceStorage) SetReference(ref *plumbing.Reference) error {
	if ref != nil {
		r[ref.Name()] = ref
	}

	return nil
}
示例#2
0
文件: proxy.go 项目: mcuadros/gop.kg
func (s *Server) buildGitUploadPackInfo(ref *plumbing.Reference) *common.GitUploadPackInfo {
	info := common.NewGitUploadPackInfo()
	info.Refs.SetReference(ref)
	info.Refs.SetReference(plumbing.NewSymbolicReference(plumbing.HEAD, ref.Name()))
	info.Capabilities.Set("symref", "HEAD:"+ref.Name().String())

	return info
}
示例#3
0
文件: advrefs.go 项目: src-d/go-git
func (a *AdvRefs) AddReference(r *plumbing.Reference) error {
	switch r.Type() {
	case plumbing.SymbolicReference:
		v := fmt.Sprintf("%s:%s", r.Name().String(), r.Target().String())
		a.Capabilities.Add(capability.SymRef, v)
	case plumbing.HashReference:
		a.References[r.Name().String()] = r.Hash()
	default:
		return plumbing.ErrInvalidType
	}

	return nil
}
示例#4
0
func (r *Repository) createReferences(ref *plumbing.Reference) error {
	if !ref.IsBranch() {
		// detached HEAD mode
		head := plumbing.NewHashReference(plumbing.HEAD, ref.Hash())
		return r.s.SetReference(head)
	}

	if err := r.s.SetReference(ref); err != nil {
		return err
	}

	head := plumbing.NewSymbolicReference(plumbing.HEAD, ref.Name())
	return r.s.SetReference(head)
}
示例#5
0
文件: storage.go 项目: src-d/go-git
func (s *Storage) SetReference(ref *plumbing.Reference) error {
	key, err := s.buildReferenceKey(ref.Name())
	if err != nil {
		return err
	}

	raw := ref.Strings()
	bins := driver.BinMap{
		urlField: s.url,
		"name":   raw[0],
		"target": raw[1],
	}

	return s.client.Put(nil, key, bins)
}
示例#6
0
文件: remote.go 项目: src-d/go-git
func (r *Remote) addReferenceIfRefSpecMatches(rs config.RefSpec,
	remoteRefs storer.ReferenceStorer, localRef *plumbing.Reference,
	req *packp.ReferenceUpdateRequest) error {

	if localRef.Type() != plumbing.HashReference {
		return nil
	}

	if !rs.Match(localRef.Name()) {
		return nil
	}

	dstName := rs.Dst(localRef.Name())
	oldHash := plumbing.ZeroHash
	newHash := localRef.Hash()

	iter, err := remoteRefs.IterReferences()
	if err != nil {
		return err
	}

	err = iter.ForEach(func(remoteRef *plumbing.Reference) error {
		if remoteRef.Type() != plumbing.HashReference {
			return nil
		}

		if dstName != remoteRef.Name() {
			return nil
		}

		oldHash = remoteRef.Hash()
		return nil
	})

	if oldHash == newHash {
		return nil
	}

	req.Commands = append(req.Commands, &packp.Command{
		Name: dstName,
		Old:  oldHash,
		New:  newHash,
	})
	return nil
}
示例#7
0
func (d *DotGit) SetRef(r *plumbing.Reference) error {
	var content string
	switch r.Type() {
	case plumbing.SymbolicReference:
		content = fmt.Sprintf("ref: %s\n", r.Target())
	case plumbing.HashReference:
		content = fmt.Sprintln(r.Hash().String())
	}

	f, err := d.fs.Create(r.Name().String())
	if err != nil {
		return err
	}

	if _, err := f.Write([]byte(content)); err != nil {
		return err
	}
	return f.Close()
}