aboutsummaryrefslogtreecommitdiffstats
path: root/storage/filesystem
diff options
context:
space:
mode:
Diffstat (limited to 'storage/filesystem')
-rw-r--r--storage/filesystem/internal/dotgit/dotgit.go2
-rw-r--r--storage/filesystem/storage.go14
-rw-r--r--storage/filesystem/storage_test.go19
3 files changed, 18 insertions, 17 deletions
diff --git a/storage/filesystem/internal/dotgit/dotgit.go b/storage/filesystem/internal/dotgit/dotgit.go
index 7db5aa6..827c18d 100644
--- a/storage/filesystem/internal/dotgit/dotgit.go
+++ b/storage/filesystem/internal/dotgit/dotgit.go
@@ -231,7 +231,7 @@ func (d *DotGit) Objects() ([]plumbing.Hash, error) {
return objects, nil
}
-// Object return a fs.File poiting the object file, if exists
+// Object return a fs.File pointing the object file, if exists
func (d *DotGit) Object(h plumbing.Hash) (billy.File, error) {
hash := h.String()
file := d.fs.Join(objectsPath, hash[0:2], hash[2:40])
diff --git a/storage/filesystem/storage.go b/storage/filesystem/storage.go
index dcb061d..768238e 100644
--- a/storage/filesystem/storage.go
+++ b/storage/filesystem/storage.go
@@ -11,7 +11,8 @@ import (
// standard git format (this is, the .git directory). Zero values of this type
// are not safe to use, see the NewStorage function below.
type Storage struct {
- fs billy.Filesystem
+ fs billy.Filesystem
+ dir *dotgit.DotGit
ObjectStorage
ReferenceStorage
@@ -24,17 +25,14 @@ type Storage struct {
// NewStorage returns a new Storage backed by a given `fs.Filesystem`
func NewStorage(fs billy.Filesystem) (*Storage, error) {
dir := dotgit.New(fs)
- if err := dir.Initialize(); err != nil {
- return nil, err
- }
-
o, err := newObjectStorage(dir)
if err != nil {
return nil, err
}
return &Storage{
- fs: fs,
+ fs: fs,
+ dir: dir,
ObjectStorage: o,
ReferenceStorage: ReferenceStorage{dir: dir},
@@ -49,3 +47,7 @@ func NewStorage(fs billy.Filesystem) (*Storage, error) {
func (s *Storage) Filesystem() billy.Filesystem {
return s.fs
}
+
+func (s *Storage) Init() error {
+ return s.dir.Initialize()
+}
diff --git a/storage/filesystem/storage_test.go b/storage/filesystem/storage_test.go
index 0127489..03d2e86 100644
--- a/storage/filesystem/storage_test.go
+++ b/storage/filesystem/storage_test.go
@@ -1,6 +1,7 @@
package filesystem
import (
+ "io/ioutil"
"testing"
"gopkg.in/src-d/go-git.v4/storage/test"
@@ -14,31 +15,29 @@ func Test(t *testing.T) { TestingT(t) }
type StorageSuite struct {
test.BaseStorageSuite
+ dir string
}
var _ = Suite(&StorageSuite{})
func (s *StorageSuite) SetUpTest(c *C) {
- storage, err := NewStorage(osfs.New(c.MkDir()))
+ s.dir = c.MkDir()
+ storage, err := NewStorage(osfs.New(s.dir))
c.Assert(err, IsNil)
s.BaseStorageSuite = test.NewBaseStorageSuite(storage)
}
-func (s *StorageSuite) TestNewStorage(c *C) {
+func (s *StorageSuite) TestFilesystem(c *C) {
fs := memfs.New()
storage, err := NewStorage(fs)
c.Assert(err, IsNil)
- c.Assert(storage, NotNil)
- _, err = fs.Stat("refs/tags")
- c.Assert(err, IsNil)
+ c.Assert(storage.Filesystem(), Equals, fs)
}
-func (s *StorageSuite) TestFilesystem(c *C) {
- fs := memfs.New()
- storage, err := NewStorage(fs)
+func (s *StorageSuite) TestNewStorageShouldNotAddAnyContentsToDir(c *C) {
+ fis, err := ioutil.ReadDir(s.dir)
c.Assert(err, IsNil)
-
- c.Assert(storage.Filesystem(), Equals, fs)
+ c.Assert(fis, HasLen, 0)
}