func (s *ConfigSuite) SetUpTest(c *C) { tmp, err := ioutil.TempDir("", "go-git-filestystem-config") c.Assert(err, IsNil) s.dir = dotgit.New(os.New(tmp)) s.path = tmp }
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) }
func (s *FsSuite) TestGetFromPackfile(c *C) { fixtures.Basic().ByTag(".git").Test(c, func(f *fixtures.Fixture) { fs := f.DotGit() o, err := newObjectStorage(dotgit.New(fs)) c.Assert(err, IsNil) expected := plumbing.NewHash("6ecf0ef2c2dffb796033e5a02219af86ec6584e5") obj, err := o.Object(plumbing.AnyObject, expected) c.Assert(err, IsNil) c.Assert(obj.Hash(), Equals, expected) }) }
// NewStorage returns a new Storage backed by a given `fs.Filesystem` func NewStorage(fs fs.Filesystem) (*Storage, error) { dir := dotgit.New(fs) o, err := newObjectStorage(dir) if err != nil { return nil, err } return &Storage{ ObjectStorage: o, ReferenceStorage: ReferenceStorage{dir: dir}, ConfigStorage: ConfigStorage{dir: dir}, }, nil }
func (s *ConfigSuite) TestRemotes(c *C) { dir := dotgit.New(fixtures.Basic().ByTag(".git").One().DotGit()) storer := &ConfigStorage{dir} cfg, err := storer.Config() c.Assert(err, IsNil) remotes := cfg.Remotes c.Assert(remotes, HasLen, 1) remote := remotes["origin"] c.Assert(remote.Name, Equals, "origin") c.Assert(remote.URL, Equals, "https://github.com/git-fixtures/basic") c.Assert(remote.Fetch, HasLen, 1) c.Assert(remote.Fetch[0].String(), Equals, "+refs/heads/*:refs/remotes/origin/*") }
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) }
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) }) }
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) }) }