forked from go-git/go-git
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathprune_test.go
79 lines (64 loc) · 1.66 KB
/
prune_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
package git
import (
"testing"
"time"
"github.com/go-git/go-git/v5/plumbing"
"github.com/go-git/go-git/v5/plumbing/cache"
"github.com/go-git/go-git/v5/plumbing/storer"
"github.com/go-git/go-git/v5/storage"
"github.com/go-git/go-git/v5/storage/filesystem"
"github.com/stretchr/testify/suite"
fixtures "github.com/go-git/go-git-fixtures/v4"
)
type PruneSuite struct {
suite.Suite
BaseSuite
}
func TestPruneSuite(t *testing.T) {
suite.Run(t, new(PruneSuite))
}
func (s *PruneSuite) testPrune(deleteTime time.Time) {
srcFs := fixtures.ByTag("unpacked").One().DotGit()
var sto storage.Storer
var err error
sto = filesystem.NewStorage(srcFs, cache.NewObjectLRUDefault())
los := sto.(storer.LooseObjectStorer)
s.NotNil(los)
count := 0
err = los.ForEachObjectHash(func(_ plumbing.Hash) error {
count++
return nil
})
s.NoError(err)
r, err := Open(sto, srcFs)
s.NoError(err)
s.NotNil(r)
// Remove a branch so we can prune some objects.
err = sto.RemoveReference(plumbing.ReferenceName("refs/heads/v4"))
s.NoError(err)
err = sto.RemoveReference(plumbing.ReferenceName("refs/remotes/origin/v4"))
s.NoError(err)
err = r.Prune(PruneOptions{
OnlyObjectsOlderThan: deleteTime,
Handler: r.DeleteObject,
})
s.NoError(err)
newCount := 0
err = los.ForEachObjectHash(func(_ plumbing.Hash) error {
newCount++
return nil
})
s.NoError(err)
if deleteTime.IsZero() {
s.True(newCount < count)
} else {
// Assume a delete time older than any of the objects was passed in.
s.Equal(count, newCount)
}
}
func (s *PruneSuite) TestPrune() {
s.testPrune(time.Time{})
}
func (s *PruneSuite) TestPruneWithNoDelete() {
s.testPrune(time.Unix(0, 1))
}