diff options
author | Jeremy Stribling <strib@alum.mit.edu> | 2017-11-29 14:52:01 -0800 |
---|---|---|
committer | Jeremy Stribling <strib@alum.mit.edu> | 2017-11-29 16:04:09 -0800 |
commit | 88acc31c76a3033a4d02e0d6cc751c74b9aeeea5 (patch) | |
tree | a2ae4d5027f28f26e46f2ae0e8c5a74ab37eaee4 /repository_test.go | |
parent | 4c1569511db5e1d26e42e9cd8dadb9e65ccafb20 (diff) | |
download | go-git-88acc31c76a3033a4d02e0d6cc751c74b9aeeea5.tar.gz |
repository: add tests for pruning and object re-packing
Also, object re-packing should clean up any loose objects that were
packed.
Diffstat (limited to 'repository_test.go')
-rw-r--r-- | repository_test.go | 61 |
1 files changed, 61 insertions, 0 deletions
diff --git a/repository_test.go b/repository_test.go index 9d82651..2ebc597 100644 --- a/repository_test.go +++ b/repository_test.go @@ -10,10 +10,13 @@ import ( "os/exec" "path/filepath" "strings" + "time" "gopkg.in/src-d/go-git.v4/config" "gopkg.in/src-d/go-git.v4/plumbing" "gopkg.in/src-d/go-git.v4/plumbing/object" + "gopkg.in/src-d/go-git.v4/plumbing/storer" + "gopkg.in/src-d/go-git.v4/storage" "gopkg.in/src-d/go-git.v4/storage/filesystem" "gopkg.in/src-d/go-git.v4/storage/memory" @@ -1313,6 +1316,64 @@ func (s *RepositorySuite) TestResolveRevisionWithErrors(c *C) { } } +func (s *RepositorySuite) testRepackObjects( + c *C, deleteTime time.Time, expectedPacks int) { + srcFs := fixtures.ByTag("unpacked").One().DotGit() + var sto storage.Storer + var err error + sto, err = filesystem.NewStorage(srcFs) + c.Assert(err, IsNil) + + los := sto.(storer.LooseObjectStorer) + c.Assert(los, NotNil) + + numLooseStart := 0 + err = los.ForEachObjectHash(func(_ plumbing.Hash) error { + numLooseStart++ + return nil + }) + c.Assert(err, IsNil) + c.Assert(numLooseStart > 0, Equals, true) + + pos := sto.(storer.PackedObjectStorer) + c.Assert(los, NotNil) + + packs, err := pos.ObjectPacks() + c.Assert(err, IsNil) + numPacksStart := len(packs) + c.Assert(numPacksStart > 1, Equals, true) + + r, err := Open(sto, srcFs) + c.Assert(err, IsNil) + c.Assert(r, NotNil) + + err = r.RepackObjects(&RepackConfig{ + OnlyDeletePacksOlderThan: deleteTime, + }) + c.Assert(err, IsNil) + + numLooseEnd := 0 + err = los.ForEachObjectHash(func(_ plumbing.Hash) error { + numLooseEnd++ + return nil + }) + c.Assert(err, IsNil) + c.Assert(numLooseEnd, Equals, 0) + + packs, err = pos.ObjectPacks() + c.Assert(err, IsNil) + numPacksEnd := len(packs) + c.Assert(numPacksEnd, Equals, expectedPacks) +} + +func (s *RepositorySuite) TestRepackObjects(c *C) { + s.testRepackObjects(c, time.Time{}, 1) +} + +func (s *RepositorySuite) TestRepackObjectsWithNoDelete(c *C) { + s.testRepackObjects(c, time.Unix(0, 1), 3) +} + func ExecuteOnPath(c *C, path string, cmds ...string) error { for _, cmd := range cmds { err := executeOnPath(path, cmd) |