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
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
|
package core
import (
"io"
. "gopkg.in/check.v1"
)
type ReferenceSuite struct{}
var _ = Suite(&ReferenceSuite{})
const (
ExampleReferenceName ReferenceName = "refs/heads/v4"
)
func (s *ReferenceSuite) TestReferenceNameAsRemote(c *C) {
c.Assert(
ExampleReferenceName.AsRemote("foo").String(),
Equals, "refs/remotes/foo/v4",
)
}
func (s *ReferenceSuite) TestNewReferenceFromStrings(c *C) {
r := NewReferenceFromStrings("refs/heads/v4", "6ecf0ef2c2dffb796033e5a02219af86ec6584e5")
c.Assert(r.Type(), Equals, HashReference)
c.Assert(r.Name(), Equals, ExampleReferenceName)
c.Assert(r.Hash(), Equals, NewHash("6ecf0ef2c2dffb796033e5a02219af86ec6584e5"))
r = NewReferenceFromStrings("HEAD", "ref: refs/heads/v4")
c.Assert(r.Type(), Equals, SymbolicReference)
c.Assert(r.Name(), Equals, HEAD)
c.Assert(r.Target(), Equals, ExampleReferenceName)
}
func (s *ReferenceSuite) TestNewSymbolicReference(c *C) {
r := NewSymbolicReference(HEAD, ExampleReferenceName)
c.Assert(r.Type(), Equals, SymbolicReference)
c.Assert(r.Name(), Equals, HEAD)
c.Assert(r.Target(), Equals, ExampleReferenceName)
}
func (s *ReferenceSuite) TestNewHashReference(c *C) {
r := NewHashReference(ExampleReferenceName, NewHash("6ecf0ef2c2dffb796033e5a02219af86ec6584e5"))
c.Assert(r.Type(), Equals, HashReference)
c.Assert(r.Name(), Equals, ExampleReferenceName)
c.Assert(r.Hash(), Equals, NewHash("6ecf0ef2c2dffb796033e5a02219af86ec6584e5"))
}
func (s *ReferenceSuite) TestIsBranch(c *C) {
r := NewHashReference(ExampleReferenceName, ZeroHash)
c.Assert(r.IsBranch(), Equals, true)
}
func (s *ReferenceSuite) TestIsNote(c *C) {
r := NewHashReference(ReferenceName("refs/notes/foo"), ZeroHash)
c.Assert(r.IsNote(), Equals, true)
}
func (s *ReferenceSuite) TestIsRemote(c *C) {
r := NewHashReference(ReferenceName("refs/remotes/origin/master"), ZeroHash)
c.Assert(r.IsRemote(), Equals, true)
}
func (s *ReferenceSuite) TestIsTag(c *C) {
r := NewHashReference(ReferenceName("refs/tags/v3.1."), ZeroHash)
c.Assert(r.IsTag(), Equals, true)
}
func (s *ReferenceSuite) TestReferenceSliceIterNext(c *C) {
slice := []*Reference{
NewReferenceFromStrings("foo", "foo"),
NewReferenceFromStrings("bar", "bar"),
}
i := NewReferenceSliceIter(slice)
foo, err := i.Next()
c.Assert(err, IsNil)
c.Assert(foo == slice[0], Equals, true)
bar, err := i.Next()
c.Assert(err, IsNil)
c.Assert(bar == slice[1], Equals, true)
empty, err := i.Next()
c.Assert(err, Equals, io.EOF)
c.Assert(empty, IsNil)
}
func (s *ReferenceSuite) TestReferenceSliceIterForEach(c *C) {
slice := []*Reference{
NewReferenceFromStrings("foo", "foo"),
NewReferenceFromStrings("bar", "bar"),
}
i := NewReferenceSliceIter(slice)
var count int
i.ForEach(func(r *Reference) error {
c.Assert(r == slice[count], Equals, true)
count++
return nil
})
c.Assert(count, Equals, 2)
}
func (s *ReferenceSuite) TestReferenceSliceIterForEachStop(c *C) {
slice := []*Reference{
NewReferenceFromStrings("foo", "foo"),
NewReferenceFromStrings("bar", "bar"),
}
i := NewReferenceSliceIter(slice)
var count int
i.ForEach(func(r *Reference) error {
c.Assert(r == slice[count], Equals, true)
count++
return ErrStop
})
c.Assert(count, Equals, 1)
}
func (s *ReferenceSuite) TestRefSpecIsValid(c *C) {
spec := RefSpec("+refs/heads/*:refs/remotes/origin/*")
c.Assert(spec.IsValid(), Equals, true)
spec = RefSpec("refs/heads/*:refs/remotes/origin/")
c.Assert(spec.IsValid(), Equals, false)
spec = RefSpec("refs/heads/master:refs/remotes/origin/master")
c.Assert(spec.IsValid(), Equals, true)
spec = RefSpec("refs/heads/*")
c.Assert(spec.IsValid(), Equals, false)
}
func (s *ReferenceSuite) TestRefSpecIsForceUpdate(c *C) {
spec := RefSpec("+refs/heads/*:refs/remotes/origin/*")
c.Assert(spec.IsForceUpdate(), Equals, true)
spec = RefSpec("refs/heads/*:refs/remotes/origin/*")
c.Assert(spec.IsForceUpdate(), Equals, false)
}
func (s *ReferenceSuite) TestRefSpecSrc(c *C) {
spec := RefSpec("refs/heads/*:refs/remotes/origin/*")
c.Assert(spec.Src(), Equals, "refs/heads/*")
}
func (s *ReferenceSuite) TestRefSpecMatch(c *C) {
spec := RefSpec("refs/heads/master:refs/remotes/origin/master")
c.Assert(spec.Match(ReferenceName("refs/heads/foo")), Equals, false)
c.Assert(spec.Match(ReferenceName("refs/heads/master")), Equals, true)
}
func (s *ReferenceSuite) TestRefSpecMatchBlob(c *C) {
spec := RefSpec("refs/heads/*:refs/remotes/origin/*")
c.Assert(spec.Match(ReferenceName("refs/tag/foo")), Equals, false)
c.Assert(spec.Match(ReferenceName("refs/heads/foo")), Equals, true)
}
func (s *ReferenceSuite) TestRefSpecDst(c *C) {
spec := RefSpec("refs/heads/master:refs/remotes/origin/master")
c.Assert(
spec.Dst(ReferenceName("refs/heads/master")).String(), Equals,
"refs/remotes/origin/master",
)
}
func (s *ReferenceSuite) TestRefSpecDstBlob(c *C) {
spec := RefSpec("refs/heads/*:refs/remotes/origin/*")
c.Assert(
spec.Dst(ReferenceName("refs/heads/foo")).String(), Equals,
"refs/remotes/origin/foo",
)
}
|