Example #1
0
func (s *AdvRefSuite) TestAllReferences(c *C) {
	hash := plumbing.NewHash("5dc01c595e6c6ec9ccda4f6f69c131c0dd945f8c")

	a := NewAdvRefs()
	err := a.AddReference(plumbing.NewSymbolicReference("foo", "bar"))
	c.Assert(err, IsNil)
	err = a.AddReference(plumbing.NewHashReference("bar", hash))
	c.Assert(err, IsNil)

	refs, err := a.AllReferences()
	c.Assert(err, IsNil)

	iter, err := refs.IterReferences()
	c.Assert(err, IsNil)

	var count int
	iter.ForEach(func(ref *plumbing.Reference) error {
		count++
		switch ref.Name() {
		case "bar":
			c.Assert(ref.Hash(), Equals, hash)
		case "foo":
			c.Assert(ref.Target().String(), Equals, "bar")
		}
		return nil
	})

	c.Assert(count, Equals, 2)
}
Example #2
0
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
}
Example #3
0
func (s *AdvRefSuite) TestAddReferenceSymbolic(c *C) {
	ref := plumbing.NewSymbolicReference("foo", "bar")

	a := NewAdvRefs()
	err := a.AddReference(ref)
	c.Assert(err, IsNil)

	values := a.Capabilities.Get(capability.SymRef)
	c.Assert(values, HasLen, 1)
	c.Assert(values[0], Equals, "foo:bar")
}
Example #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)
}
Example #5
0
func (s *SuiteCommon) TestGitUploadPackEncode(c *C) {
	info := NewGitUploadPackInfo()
	info.Capabilities.Add("symref", "HEAD:refs/heads/master")

	ref := plumbing.ReferenceName("refs/heads/master")
	hash := plumbing.NewHash("6ecf0ef2c2dffb796033e5a02219af86ec6584e5")
	info.Refs = map[plumbing.ReferenceName]*plumbing.Reference{
		plumbing.HEAD: plumbing.NewSymbolicReference(plumbing.HEAD, ref),
		ref:           plumbing.NewHashReference(ref, hash),
	}

	c.Assert(info.Head(), NotNil)
	c.Assert(info.String(), Equals,
		"001e# service=git-upload-pack\n"+
			"000000506ecf0ef2c2dffb796033e5a02219af86ec6584e5 HEAD\x00symref=HEAD:refs/heads/master\n"+
			"003f6ecf0ef2c2dffb796033e5a02219af86ec6584e5 refs/heads/master\n"+
			"0000",
	)
}
Example #6
0
func (i *GitUploadPackInfo) addSymbolicRefs(ar *advrefs.AdvRefs) error {
	if !hasSymrefs(ar) {
		return nil
	}

	for _, symref := range ar.Capabilities.Get("symref").Values {
		chunks := strings.Split(symref, ":")
		if len(chunks) != 2 {
			err := fmt.Errorf("bad number of `:` in symref value (%q)", symref)
			return plumbing.NewUnexpectedError(err)
		}
		name := plumbing.ReferenceName(chunks[0])
		target := plumbing.ReferenceName(chunks[1])
		ref := plumbing.NewSymbolicReference(name, target)
		i.Refs.SetReference(ref)
	}

	return nil
}
Example #7
0
func addSymbolicRefs(s storer.ReferenceStorer, ar *AdvRefs) error {
	if !hasSymrefs(ar) {
		return nil
	}

	for _, symref := range ar.Capabilities.Get(capability.SymRef) {
		chunks := strings.Split(symref, ":")
		if len(chunks) != 2 {
			err := fmt.Errorf("bad number of `:` in symref value (%q)", symref)
			return plumbing.NewUnexpectedError(err)
		}
		name := plumbing.ReferenceName(chunks[0])
		target := plumbing.ReferenceName(chunks[1])
		ref := plumbing.NewSymbolicReference(name, target)
		if err := s.SetReference(ref); err != nil {
			return nil
		}
	}

	return nil
}
Example #8
0
func (p *MockGitUploadPackService) Info() (*common.GitUploadPackInfo, error) {
	if !p.connected {
		return nil, errors.New("not connected")
	}

	h := fixtures.ByURL(p.endpoint.String()).One().Head

	c := packp.NewCapabilities()
	c.Decode("6ecf0ef2c2dffb796033e5a02219af86ec6584e5 HEADmulti_ack thin-pack side-band side-band-64k ofs-delta shallow no-progress include-tag multi_ack_detailed no-done symref=HEAD:refs/heads/master agent=git/2:2.4.8~dbussink-fix-enterprise-tokens-compilation-1167-gc7006cf")

	ref := plumbing.ReferenceName("refs/heads/master")
	branch := plumbing.ReferenceName("refs/heads/branch")
	tag := plumbing.ReferenceName("refs/tags/v1.0.0")

	return &common.GitUploadPackInfo{
		Capabilities: c,
		Refs: map[plumbing.ReferenceName]*plumbing.Reference{
			plumbing.HEAD: plumbing.NewSymbolicReference(plumbing.HEAD, ref),
			ref:           plumbing.NewHashReference(ref, h),
			tag:           plumbing.NewHashReference(tag, h),
			branch:        plumbing.NewHashReference(branch, plumbing.NewHash("e8d3ffab552895c19b9fcf7aa264d277cde33881")),
		},
	}, nil
}