Ejemplo n.º 1
0
func (s *SuiteCommon) TestNewVersions(c *C) {
	refs := make(memory.ReferenceStorage, 0)
	refs.SetReference(plumbing.NewHashReference("refs/heads/master", plumbing.NewHash("")))
	refs.SetReference(plumbing.NewHashReference("refs/tags/v1.0.0", plumbing.NewHash("")))
	refs.SetReference(plumbing.NewHashReference("refs/tags/1.1.2", plumbing.NewHash("")))
	refs.SetReference(plumbing.NewHashReference("refs/tags/1.1.3", plumbing.NewHash("")))
	refs.SetReference(plumbing.NewHashReference("refs/tags/v1.0.3", plumbing.NewHash("")))
	refs.SetReference(plumbing.NewHashReference("refs/tags/v2.0.3", plumbing.NewHash("")))
	refs.SetReference(plumbing.NewHashReference("refs/tags/v4.0.0-rc1", plumbing.NewHash("")))

	v := NewVersions(refs)
	c.Assert(v.BestMatch("v0").Name().String(), Equals, "refs/heads/master")
	c.Assert(v.BestMatch("v1.1").Name().String(), Equals, "refs/tags/1.1.3")
	c.Assert(v.BestMatch("1.1").Name().String(), Equals, "refs/tags/1.1.3")
	c.Assert(v.BestMatch("1.1.2").Name().String(), Equals, "refs/tags/1.1.2")
	c.Assert(v.BestMatch("2").Name().String(), Equals, "refs/tags/v2.0.3")
	c.Assert(v.BestMatch("4").Name().String(), Equals, "refs/tags/v4.0.0-rc1")
	c.Assert(v.BestMatch("master").Name().String(), Equals, "refs/heads/master")
	c.Assert(v.BestMatch("foo"), IsNil)

	refs.SetReference(plumbing.NewHashReference("refs/tags/v0.0.0", plumbing.NewHash("")))

	v = NewVersions(refs)
	c.Assert(v.BestMatch("v0").Name().String(), Equals, "refs/tags/v0.0.0")
}
Ejemplo n.º 2
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)
}
Ejemplo n.º 3
0
func (s *AdvRefSuite) TestAddReferenceHash(c *C) {
	ref := plumbing.NewHashReference("foo", plumbing.NewHash("5dc01c595e6c6ec9ccda4f6f69c131c0dd945f8c"))

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

	c.Assert(a.References, HasLen, 1)
	c.Assert(a.References["foo"].String(), Equals, "5dc01c595e6c6ec9ccda4f6f69c131c0dd945f8c")
}
Ejemplo n.º 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)
}
Ejemplo n.º 5
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
}
Ejemplo n.º 6
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",
	)
}
Ejemplo n.º 7
0
func (r *Remote) updateLocalReferenceStorage(specs []config.RefSpec, refs memory.ReferenceStorage) error {
	for _, spec := range specs {
		for _, ref := range refs {
			if !spec.Match(ref.Name()) {
				continue
			}

			if ref.Type() != plumbing.HashReference {
				continue
			}

			name := spec.Dst(ref.Name())
			n := plumbing.NewHashReference(name, ref.Hash())
			if err := r.s.SetReference(n); err != nil {
				return err
			}
		}
	}

	return r.buildFetchedTags(refs)
}
Ejemplo n.º 8
0
// we mutate the tag into a branch to avoid detached branches
func (s *Server) mutateTagToBranch(ref *plumbing.Reference, constraint string) *plumbing.Reference {
	branch := plumbing.ReferenceName(fmt.Sprintf("refs/heads/%s", constraint))
	return plumbing.NewHashReference(branch, ref.Hash())
}