Ejemplo n.º 1
0
func (s *FetchPackSuite) SetUpSuite(c *C) {
	s.Suite.SetUpSuite(c)

	if err := exec.Command("git", "--version").Run(); err != nil {
		c.Skip("git command not found")
	}

	s.FetchPackSuite.Client = DefaultClient

	fixture := fixtures.Basic().One()
	path := fixture.DotGit().Base()
	url := fmt.Sprintf("file://%s", path)
	ep, err := transport.NewEndpoint(url)
	c.Assert(err, IsNil)
	s.Endpoint = ep

	fixture = fixtures.ByTag("empty").One()
	path = fixture.DotGit().Base()
	url = fmt.Sprintf("file://%s", path)
	ep, err = transport.NewEndpoint(url)
	c.Assert(err, IsNil)
	s.EmptyEndpoint = ep

	url = fmt.Sprintf("file://%s/%s", fixtures.DataFolder, "non-existent")
	ep, err = transport.NewEndpoint(url)
	c.Assert(err, IsNil)
	s.NonExistentEndpoint = ep
}
Ejemplo n.º 2
0
func (s *SuiteDotGit) TestObjectNotFound(c *C) {
	fs := fixtures.ByTag(".git").ByTag("unpacked").One().DotGit()
	dir := New(fs)

	hash := plumbing.NewHash("not-found-object")
	file, err := dir.Object(hash)
	c.Assert(err, NotNil)
	c.Assert(file, IsNil)
}
Ejemplo n.º 3
0
func (s *FsSuite) TestGetFromObjectFile(c *C) {
	fs := fixtures.ByTag(".git").ByTag("unpacked").One().DotGit()
	o, err := newObjectStorage(dotgit.New(fs))
	c.Assert(err, IsNil)

	expected := plumbing.NewHash("f3dfe29d268303fc6e1bbce268605fc99573406e")
	obj, err := o.Object(plumbing.AnyObject, expected)
	c.Assert(err, IsNil)
	c.Assert(obj.Hash(), Equals, expected)
}
Ejemplo n.º 4
0
func (s *SuiteDotGit) TestObjects(c *C) {
	fs := fixtures.ByTag(".git").ByTag("unpacked").One().DotGit()
	dir := New(fs)

	hashes, err := dir.Objects()
	c.Assert(err, IsNil)
	c.Assert(hashes, HasLen, 187)
	c.Assert(hashes[0].String(), Equals, "0097821d427a3c3385898eb13b50dcbc8702b8a3")
	c.Assert(hashes[1].String(), Equals, "01d5fa556c33743006de7e76e67a2dfcd994ca04")
	c.Assert(hashes[2].String(), Equals, "03db8e1fbe133a480f2867aac478fd866686d69e")
}
Ejemplo n.º 5
0
func (s *SendPackSuite) SetUpTest(c *C) {
	fixture := fixtures.Basic().One()
	path := fixture.DotGit().Base()
	s.Endpoint = prepareRepo(c, path)

	fixture = fixtures.ByTag("empty").One()
	path = fixture.DotGit().Base()
	s.EmptyEndpoint = prepareRepo(c, path)

	s.NonExistentEndpoint = prepareRepo(c, "/non-existent")
}
Ejemplo n.º 6
0
func (s *SuiteDotGit) TestObject(c *C) {
	fs := fixtures.ByTag(".git").ByTag("unpacked").One().DotGit()
	dir := New(fs)

	hash := plumbing.NewHash("03db8e1fbe133a480f2867aac478fd866686d69e")
	file, err := dir.Object(hash)
	c.Assert(err, IsNil)
	c.Assert(strings.HasSuffix(
		file.Filename(), "objects/03/db8e1fbe133a480f2867aac478fd866686d69e"),
		Equals, true,
	)
}
Ejemplo n.º 7
0
func (s *FsSuite) TestGetFromPackfileMultiplePackfiles(c *C) {
	fs := fixtures.ByTag(".git").ByTag("multi-packfile").One().DotGit()
	o, err := newObjectStorage(dotgit.New(fs))
	c.Assert(err, IsNil)

	expected := plumbing.NewHash("8d45a34641d73851e01d3754320b33bb5be3c4d3")
	obj, err := o.getFromPackfile(expected)
	c.Assert(err, IsNil)
	c.Assert(obj.Hash(), Equals, expected)

	expected = plumbing.NewHash("e9cfa4c9ca160546efd7e8582ec77952a27b17db")
	obj, err = o.getFromPackfile(expected)
	c.Assert(err, IsNil)
	c.Assert(obj.Hash(), Equals, expected)
}
Ejemplo n.º 8
0
func (s *FsSuite) TestIterWithType(c *C) {
	fixtures.ByTag(".git").Test(c, func(f *fixtures.Fixture) {
		fs := f.DotGit()
		o, err := newObjectStorage(dotgit.New(fs))
		c.Assert(err, IsNil)

		iter, err := o.IterObjects(plumbing.CommitObject)
		c.Assert(err, IsNil)

		err = iter.ForEach(func(o plumbing.Object) error {
			c.Assert(o.Type(), Equals, plumbing.CommitObject)
			return nil
		})

		c.Assert(err, IsNil)
	})
}
Ejemplo n.º 9
0
// It is difficult to assert that we are ignoring an (empty) dir as even
// if we don't, no files will be found in it.
//
// At least this test has a high chance of panicking if
// we don't ignore empty dirs.
func (s *FileSuite) TestIgnoreEmptyDirEntries(c *C) {
	s.buildRepositories(c, fixtures.ByTag("empty-folder"))

	for i, t := range ignoreEmptyDirEntriesTests {
		commit, err := s.Repositories[t.repo].Commit(plumbing.NewHash(t.commit))
		c.Assert(err, IsNil, Commentf("subtest %d: %v (%s)", i, err, t.commit))

		tree, err := commit.Tree()
		c.Assert(err, IsNil)

		iter := tree.Files()
		defer iter.Close()
		for file, err := iter.Next(); err == nil; file, err = iter.Next() {
			_, _ = file.Contents()
			// this would probably panic if we are not ignoring empty dirs
		}
	}
}
Ejemplo n.º 10
0
func (s *IdxfileSuite) TestDecodeEncode(c *C) {
	fixtures.ByTag("packfile").Test(c, func(f *fixtures.Fixture) {
		expected, err := ioutil.ReadAll(f.Idx())
		c.Assert(err, IsNil)

		idx := &Idxfile{}
		d := NewDecoder(bytes.NewBuffer(expected))
		err = d.Decode(idx)
		c.Assert(err, IsNil)

		result := bytes.NewBuffer(nil)
		e := NewEncoder(result)
		size, err := e.Encode(idx)
		c.Assert(err, IsNil)

		c.Assert(size, Equals, len(expected))
		c.Assert(result.Bytes(), DeepEquals, expected)
	})
}
Ejemplo n.º 11
0
func (s *FsSuite) TestIter(c *C) {
	fixtures.ByTag(".git").ByTag("packfile").Test(c, func(f *fixtures.Fixture) {
		fs := f.DotGit()
		o, err := newObjectStorage(dotgit.New(fs))
		c.Assert(err, IsNil)

		iter, err := o.IterObjects(plumbing.AnyObject)
		c.Assert(err, IsNil)

		var count int32
		err = iter.ForEach(func(o plumbing.Object) error {
			count++
			return nil
		})

		c.Assert(err, IsNil)
		c.Assert(count, Equals, f.ObjectsCount)
	})
}
Ejemplo n.º 12
0
func (s *RepositorySuite) TestPushToEmptyRepository(c *C) {
	srcFs := fixtures.Basic().One().DotGit()
	sto, err := filesystem.NewStorage(srcFs)
	c.Assert(err, IsNil)

	dstFs := fixtures.ByTag("empty").One().DotGit()
	url := fmt.Sprintf("file://%s", dstFs.Base())

	r, err := NewRepository(sto)
	c.Assert(err, IsNil)

	_, err = r.CreateRemote(&config.RemoteConfig{
		Name: "myremote",
		URL:  url,
	})
	c.Assert(err, IsNil)

	err = r.Push(&PushOptions{RemoteName: "myremote"})
	c.Assert(err, IsNil)

	sto, err = filesystem.NewStorage(dstFs)
	c.Assert(err, IsNil)
	dstRepo, err := NewRepository(sto)
	c.Assert(err, IsNil)

	iter, err := sto.IterReferences()
	c.Assert(err, IsNil)
	err = iter.ForEach(func(ref *plumbing.Reference) error {
		if !ref.IsBranch() {
			return nil
		}

		dstRef, err := dstRepo.Reference(ref.Name(), true)
		c.Assert(err, IsNil)
		c.Assert(dstRef, DeepEquals, ref)

		return nil
	})
	c.Assert(err, IsNil)
}
Ejemplo n.º 13
0
func (s *RemoteSuite) TestPushToEmptyRepository(c *C) {
	srcFs := fixtures.Basic().One().DotGit()
	sto, err := filesystem.NewStorage(srcFs)
	c.Assert(err, IsNil)

	dstFs := fixtures.ByTag("empty").One().DotGit()
	url := fmt.Sprintf("file://%s", dstFs.Base())

	r := newRemote(sto, nil, &config.RemoteConfig{
		Name: DefaultRemoteName,
		URL:  url,
	})

	rs := config.RefSpec("refs/heads/*:refs/heads/*")
	err = r.Push(&PushOptions{
		RefSpecs: []config.RefSpec{rs},
	})
	c.Assert(err, IsNil)

	dstSto, err := filesystem.NewStorage(dstFs)
	c.Assert(err, IsNil)
	dstRepo, err := NewRepository(dstSto)
	c.Assert(err, IsNil)

	iter, err := sto.IterReferences()
	c.Assert(err, IsNil)
	err = iter.ForEach(func(ref *plumbing.Reference) error {
		if !ref.IsBranch() {
			return nil
		}

		dstRef, err := dstRepo.Reference(ref.Name(), true)
		c.Assert(err, IsNil, Commentf("ref: %s", ref.String()))
		c.Assert(dstRef, DeepEquals, ref)

		return nil
	})
	c.Assert(err, IsNil)
}
Ejemplo n.º 14
0
func (s *TagSuite) SetUpSuite(c *C) {
	s.BaseSuite.SetUpSuite(c)
	s.buildRepositories(c, fixtures.ByTag("tags"))
}
Ejemplo n.º 15
0
func (s *BlameSuite) SetUpSuite(c *C) {
	s.BaseSuite.SetUpSuite(c)
	s.buildRepositories(c, fixtures.ByTag("packfile"))
}