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 /prune_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 'prune_test.go')
-rw-r--r-- | prune_test.go | 72 |
1 files changed, 72 insertions, 0 deletions
diff --git a/prune_test.go b/prune_test.go new file mode 100644 index 0000000..613fb0f --- /dev/null +++ b/prune_test.go @@ -0,0 +1,72 @@ +package git + +import ( + "time" + + "gopkg.in/src-d/go-git.v4/plumbing" + "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/check.v1" + "gopkg.in/src-d/go-git-fixtures.v3" +) + +type PruneSuite struct { + BaseSuite +} + +var _ = Suite(&PruneSuite{}) + +func (s *PruneSuite) TestPrune(c *C, deleteTime time.Time) { + 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) + + count := 0 + err = los.ForEachObjectHash(func(_ plumbing.Hash) error { + count++ + return nil + }) + c.Assert(err, IsNil) + + r, err := Open(sto, srcFs) + c.Assert(err, IsNil) + c.Assert(r, NotNil) + + // Remove a branch so we can prune some objects. + err = sto.RemoveReference(plumbing.ReferenceName("refs/heads/v4")) + c.Assert(err, IsNil) + err = sto.RemoveReference(plumbing.ReferenceName("refs/remotes/origin/v4")) + c.Assert(err, IsNil) + + err = r.Prune(PruneOptions{ + Handler: r.DeleteObject, + }) + c.Assert(err, IsNil) + + newCount := 0 + err = los.ForEachObjectHash(func(_ plumbing.Hash) error { + newCount++ + return nil + }) + if deleteTime.IsZero() { + c.Assert(newCount < count, Equals, true) + } else { + // Assume a delete time older than any of the objects was passed in. + c.Assert(newCount, Equals, count) + } +} + +func (s *PruneSuite) TestPrune(c *C) { + s.testPrune(c, time.Time{}) +} + +func (s *PruneSuite) TestPruneWithNoDelete(c *C) { + s.testPrune(c, time.Unix(0, 1)) +} |