MCPcopy
hub / github.com/nektos/act / TestGitFindRef

Function TestGitFindRef

pkg/common/git/git_test.go:102–178  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

100}
101
102func TestGitFindRef(t *testing.T) {
103 basedir := testDir(t)
104 gitConfig()
105
106 for name, tt := range map[string]struct {
107 Prepare func(t *testing.T, dir string)
108 Assert func(t *testing.T, ref string, err error)
109 }{
110 "new_repo": {
111 Prepare: func(_ *testing.T, _ string) {},
112 Assert: func(t *testing.T, _ string, err error) {
113 require.Error(t, err)
114 },
115 },
116 "new_repo_with_commit": {
117 Prepare: func(t *testing.T, dir string) {
118 require.NoError(t, gitCmd("-C", dir, "commit", "--allow-empty", "-m", "msg"))
119 },
120 Assert: func(t *testing.T, ref string, err error) {
121 require.NoError(t, err)
122 require.Equal(t, "refs/heads/master", ref)
123 },
124 },
125 "current_head_is_tag": {
126 Prepare: func(t *testing.T, dir string) {
127 require.NoError(t, gitCmd("-C", dir, "commit", "--allow-empty", "-m", "commit msg"))
128 require.NoError(t, gitCmd("-C", dir, "tag", "v1.2.3"))
129 require.NoError(t, gitCmd("-C", dir, "checkout", "v1.2.3"))
130 },
131 Assert: func(t *testing.T, ref string, err error) {
132 require.NoError(t, err)
133 require.Equal(t, "refs/tags/v1.2.3", ref)
134 },
135 },
136 "current_head_is_same_as_tag": {
137 Prepare: func(t *testing.T, dir string) {
138 require.NoError(t, gitCmd("-C", dir, "commit", "--allow-empty", "-m", "1.4.2 release"))
139 require.NoError(t, gitCmd("-C", dir, "tag", "v1.4.2"))
140 },
141 Assert: func(t *testing.T, ref string, err error) {
142 require.NoError(t, err)
143 require.Equal(t, "refs/tags/v1.4.2", ref)
144 },
145 },
146 "current_head_is_not_tag": {
147 Prepare: func(t *testing.T, dir string) {
148 require.NoError(t, gitCmd("-C", dir, "commit", "--allow-empty", "-m", "msg"))
149 require.NoError(t, gitCmd("-C", dir, "tag", "v1.4.2"))
150 require.NoError(t, gitCmd("-C", dir, "commit", "--allow-empty", "-m", "msg2"))
151 },
152 Assert: func(t *testing.T, ref string, err error) {
153 require.NoError(t, err)
154 require.Equal(t, "refs/heads/master", ref)
155 },
156 },
157 "current_head_is_another_branch": {
158 Prepare: func(t *testing.T, dir string) {
159 require.NoError(t, gitCmd("-C", dir, "checkout", "-b", "mybranch"))

Callers

nothing calls this directly

Calls 6

testDirFunction · 0.85
gitConfigFunction · 0.85
gitCmdFunction · 0.85
cleanGitHooksFunction · 0.85
FindGitRefFunction · 0.85
ErrorMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…