-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgit_up_test.go
138 lines (118 loc) · 3.38 KB
/
git_up_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
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
package gitgo_test
import (
"path/filepath"
"testing"
"github.com/go-xlan/gitgo"
"github.com/stretchr/testify/require"
"github.com/yyle88/osexistpath/osmustexist"
"github.com/yyle88/rese"
"github.com/yyle88/runpath"
)
func TestGcm_HasStagingChanges(t *testing.T) {
gcm := gitgo.New(runpath.PARENT.Path())
changes, err := gcm.HasStagingChanges()
require.NoError(t, err)
t.Log(changes)
}
func TestGcm_CheckStagedChanges(t *testing.T) {
gcm := gitgo.New(runpath.PARENT.Path())
gcm.WithDebug().
Status().
Add().
CheckStagedChanges().
ShowDebugMessage().
Status().
ShowDebugMessage()
}
func TestLatestGitTag(t *testing.T) {
gcm := gitgo.New(runpath.PARENT.Path()).WithDebug()
tag, err := gcm.LatestGitTag()
require.NoError(t, err)
t.Log(tag)
require.NotEmpty(t, tag)
}
func TestGcm_LatestGitTagHasPrefix(t *testing.T) {
gcm := gitgo.New(runpath.PARENT.Path()).WithDebug()
tag, err := gcm.LatestGitTagHasPrefix("v")
require.NoError(t, err)
t.Log(tag)
require.NotEmpty(t, tag)
}
func TestGcm_LatestGitTagHasPrefix_Compare(t *testing.T) {
gcm := gitgo.New(runpath.PARENT.Path()).WithDebug()
tagA := rese.C1(gcm.LatestGitTag())
t.Log(tagA)
tagB := rese.C1(gcm.LatestGitTagHasPrefix("v"))
t.Log(tagB)
//这里只打印,不断言相等,因为确实存在不相等的场景
t.Log("tag-A:", tagA, "tag-B:", tagB)
}
func TestGcm_LatestGitTagMatchRegexp(t *testing.T) {
gcm := gitgo.New(runpath.PARENT.Path()).WithDebug()
tag, err := gcm.LatestGitTagMatchRegexp("v[0-9]*.[0-9]*.[0-9]*")
require.NoError(t, err)
t.Log(tag)
require.NotEmpty(t, tag)
}
func TestGitCommitHash(t *testing.T) {
gcm := gitgo.New(runpath.PARENT.Path()).WithDebug()
hash, err := gcm.GitCommitHash("main")
require.NoError(t, err)
t.Log(hash)
require.NotEmpty(t, hash)
}
func TestGitCommitHash_TAG(t *testing.T) {
gcm := gitgo.New(runpath.PARENT.Path()).WithDebug()
tag, err := gcm.LatestGitTag()
require.NoError(t, err)
t.Log(tag)
require.NotEmpty(t, tag)
hash, err := gcm.GitCommitHash(tag)
require.NoError(t, err)
t.Log(hash)
require.NotEmpty(t, hash)
}
func TestGcm_SortedGitTags(t *testing.T) {
gcm := gitgo.New(runpath.PARENT.Path()).WithDebug()
tag, err := gcm.SortedGitTags()
require.NoError(t, err)
t.Log(tag)
require.NotEmpty(t, tag)
}
func TestGcm_GetTopPath(t *testing.T) {
gcm := gitgo.New(runpath.PARENT.Path()).WithDebug()
root, err := gcm.GetTopPath()
require.NoError(t, err)
t.Log(root)
require.NotEmpty(t, root)
require.Equal(t, runpath.PARENT.Path(), root)
osmustexist.MustRoot(root)
osmustexist.MustRoot(filepath.Join(root, ".git"))
}
func TestGcm_GetGitDirAbsPath(t *testing.T) {
gcm := gitgo.New(runpath.PARENT.Path()).WithDebug()
path, err := gcm.GetGitDirAbsPath()
require.NoError(t, err)
t.Log(path)
require.NotEmpty(t, path)
osmustexist.MustRoot(path)
require.Equal(t, runpath.PARENT.Join(".git"), path)
}
func TestGcm_GetSubPathToRoot(t *testing.T) {
gcm := gitgo.New(runpath.PARENT.Path()).WithDebug()
path, err := gcm.GetSubPathToRoot()
require.NoError(t, err)
t.Log(path)
require.Empty(t, path)
t.Log("sub path is the project root")
osmustexist.MustRoot(runpath.PARENT.Join(".git"))
}
func TestGcm_GetSubPath(t *testing.T) {
gcm := gitgo.New(runpath.PARENT.Path()).WithDebug()
path, err := gcm.GetSubPath()
require.NoError(t, err)
t.Log(path)
require.Empty(t, path)
t.Log("sub path is the project root")
osmustexist.MustRoot(runpath.PARENT.Join(".git"))
}