-
Notifications
You must be signed in to change notification settings - Fork 0
/
repo_test.go
103 lines (82 loc) · 2.3 KB
/
repo_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
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
package gitw_test
import (
"testing"
"github.com/gookit/gitw"
"github.com/gookit/goutil/dump"
"github.com/gookit/goutil/sysutil"
"github.com/gookit/goutil/testutil/assert"
"github.com/gookit/slog"
)
var repo = gitw.NewRepo("./").WithFn(func(r *gitw.Repo) {
r.Git().BeforeExec = gitw.PrintCmdline
})
func TestMain(m *testing.M) {
slog.Println("workdir", sysutil.Workdir())
m.Run()
}
func TestRepo_StatusInfo(t *testing.T) {
si := repo.StatusInfo()
dump.P(si)
}
func TestRepo_RemoteInfos(t *testing.T) {
rs := repo.AllRemoteInfos()
dump.P(rs)
assert.NoErr(t, repo.Err())
assert.NotEmpty(t, rs)
assert.True(t, repo.HasRemote(gitw.DefaultRemoteName))
assert.NotEmpty(t, repo.RemoteNames())
}
func TestRepo_DefaultRemoteInfo(t *testing.T) {
rt := repo.DefaultRemoteInfo()
dump.P(rt)
assert.NotEmpty(t, rt)
assert.True(t, rt.Valid())
assert.False(t, rt.Invalid())
assert.Eq(t, gitw.DefaultRemoteName, rt.Name)
assert.Eq(t, "[email protected]:gookit/gitw.git", rt.GitURL())
assert.Eq(t, "http://github.com/gookit/gitw", rt.URLOfHTTP())
assert.Eq(t, "https://github.com/gookit/gitw", rt.URLOfHTTPS())
rt = repo.RandomRemoteInfo(gitw.RemoteTypePush)
assert.NotEmpty(t, rt)
}
func TestRepo_AutoMatchTag(t *testing.T) {
assert.Eq(t, "HEAD", repo.AutoMatchTag("head"))
assert.Eq(t, "541fb9d", repo.AutoMatchTag("541fb9d"))
}
func TestRepo_BranchInfos(t *testing.T) {
bs := repo.BranchInfos()
assert.NotEmpty(t, bs)
dump.P(bs.BrLines())
assert.NotEmpty(t, repo.SearchBranches("main", gitw.BrSearchAll))
cur := repo.CurBranchInfo()
if cur != nil {
assert.NotEmpty(t, cur)
assert.NotEmpty(t, cur.Name)
}
mbr := repo.BranchInfo("main")
if mbr != nil {
assert.Eq(t, "main", mbr.Name)
assert.Eq(t, "main", mbr.Short)
}
}
func TestRepo_Info(t *testing.T) {
info := repo.Info()
dump.P(info)
assert.Nil(t, repo.Err())
assert.NotNil(t, info)
assert.Eq(t, "gitw", info.Name)
}
func TestRepo_AutoMatchTagByTagType(t *testing.T) {
assert.Eq(t, "HEAD", repo.AutoMatchTagByType("head", 0))
assert.Eq(t, "541fb9d", repo.AutoMatchTagByType("541fb9d", 0))
}
func TestRepo_TagsSortedByCreatorDate(t *testing.T) {
tags := repo.TagsSortedByCreatorDate()
dump.P(tags)
assert.NotEmpty(t, tags)
}
func TestRepo_TagByDescribe(t *testing.T) {
tags := repo.TagByDescribe("")
dump.P(tags)
assert.NotEmpty(t, tags)
}