diff options
author | Máximo Cuadros <mcuadros@gmail.com> | 2017-01-28 16:26:14 +0100 |
---|---|---|
committer | Máximo Cuadros <mcuadros@gmail.com> | 2017-01-28 16:26:14 +0100 |
commit | 9a9f2b1f63a98fad67a3190ef813428b68dfdd8c (patch) | |
tree | c7266ab8a010d551670d9f6356294c09ffa9f7fb /storage/filesystem/internal | |
parent | 24c1878260351d9f9f6c575cbeeb5878104d6a0e (diff) | |
download | go-git-9a9f2b1f63a98fad67a3190ef813428b68dfdd8c.tar.gz |
storage: IndexStorer implementation
Diffstat (limited to 'storage/filesystem/internal')
-rw-r--r-- | storage/filesystem/internal/dotgit/dotgit.go | 11 | ||||
-rw-r--r-- | storage/filesystem/internal/dotgit/dotgit_test.go | 32 |
2 files changed, 43 insertions, 0 deletions
diff --git a/storage/filesystem/internal/dotgit/dotgit.go b/storage/filesystem/internal/dotgit/dotgit.go index f9763d1..1281b7e 100644 --- a/storage/filesystem/internal/dotgit/dotgit.go +++ b/storage/filesystem/internal/dotgit/dotgit.go @@ -18,6 +18,7 @@ const ( suffix = ".git" packedRefsPath = "packed-refs" configPath = "config" + indexPath = "index" shallowPath = "shallow" objectsPath = "objects" @@ -72,6 +73,16 @@ func (d *DotGit) Config() (billy.File, error) { return d.fs.Open(configPath) } +// IndexWriter returns a file pointer for write to the index file +func (d *DotGit) IndexWriter() (billy.File, error) { + return d.fs.Create(indexPath) +} + +// Index returns a file pointer for read to the index file +func (d *DotGit) Index() (billy.File, error) { + return d.fs.Open(indexPath) +} + // ShallowWriter returns a file pointer for write to the shallow file func (d *DotGit) ShallowWriter() (billy.File, error) { return d.fs.Create(shallowPath) diff --git a/storage/filesystem/internal/dotgit/dotgit_test.go b/storage/filesystem/internal/dotgit/dotgit_test.go index 48f02f0..bff90af 100644 --- a/storage/filesystem/internal/dotgit/dotgit_test.go +++ b/storage/filesystem/internal/dotgit/dotgit_test.go @@ -154,6 +154,38 @@ func (s *SuiteDotGit) TestConfigWriteAndConfig(c *C) { c.Assert(string(cnt), Equals, "foo") } +func (s *SuiteDotGit) TestIndex(c *C) { + fs := fixtures.Basic().ByTag(".git").One().DotGit() + dir := New(fs) + + idx, err := dir.Index() + c.Assert(err, IsNil) + c.Assert(idx, NotNil) +} + +func (s *SuiteDotGit) TestIndexWriteAndIndex(c *C) { + tmp, err := ioutil.TempDir("", "dot-git") + c.Assert(err, IsNil) + defer os.RemoveAll(tmp) + + fs := osfs.New(tmp) + dir := New(fs) + + f, err := dir.IndexWriter() + c.Assert(err, IsNil) + + _, err = f.Write([]byte("foo")) + c.Assert(err, IsNil) + + f, err = dir.Index() + c.Assert(err, IsNil) + + cnt, err := ioutil.ReadAll(f) + c.Assert(err, IsNil) + + c.Assert(string(cnt), Equals, "foo") +} + func (s *SuiteDotGit) TestShallow(c *C) { fs := fixtures.Basic().ByTag(".git").One().DotGit() dir := New(fs) |