-
Notifications
You must be signed in to change notification settings - Fork 318
/
revparse_test.go
60 lines (44 loc) · 1.11 KB
/
revparse_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
package git
import (
"testing"
)
func TestRevparse(t *testing.T) {
t.Parallel()
repo := createTestRepo(t)
defer cleanupTestRepo(t, repo)
commitId, _ := seedTestRepo(t, repo)
revSpec, err := repo.Revparse("HEAD")
checkFatal(t, err)
checkObject(t, revSpec.From(), commitId)
}
func TestRevparseSingle(t *testing.T) {
t.Parallel()
repo := createTestRepo(t)
defer cleanupTestRepo(t, repo)
commitId, _ := seedTestRepo(t, repo)
obj, err := repo.RevparseSingle("HEAD")
checkFatal(t, err)
checkObject(t, obj, commitId)
}
func TestRevparseExt(t *testing.T) {
t.Parallel()
repo := createTestRepo(t)
defer cleanupTestRepo(t, repo)
_, treeId := seedTestRepo(t, repo)
ref, err := repo.References.Create("refs/heads/master", treeId, true, "")
checkFatal(t, err)
obj, ref, err := repo.RevparseExt("master")
checkFatal(t, err)
checkObject(t, obj, treeId)
if ref == nil {
t.Fatalf("bad reference")
}
}
func checkObject(t *testing.T, obj *Object, id *Oid) {
if obj == nil {
t.Fatalf("bad object")
}
if !obj.Id().Equal(id) {
t.Fatalf("bad object, expected %s, got %s", id.String(), obj.Id().String())
}
}