MCPcopy Create free account
hub / github.com/coder/envbuilder / TestShallowCloneRepo

Function TestShallowCloneRepo

git/git_test.go:192–257  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

190}
191
192func TestShallowCloneRepo(t *testing.T) {
193 t.Parallel()
194
195 t.Run("NotEmpty", func(t *testing.T) {
196 t.Parallel()
197 srvFS := memfs.New()
198 _ = gittest.NewRepo(t, srvFS,
199 gittest.Commit(t, "README.md", "Hello, world!", "Many wow!"),
200 gittest.Commit(t, "foo", "bar!", "Such commit!"),
201 gittest.Commit(t, "baz", "qux", "V nice!"),
202 )
203 authMW := mwtest.BasicAuthMW("test", "test")
204 srv := httptest.NewServer(authMW(gittest.NewServer(srvFS)))
205
206 clientFS := memfs.New()
207 // Not empty.
208 err := clientFS.MkdirAll("/repo", 0o500)
209 require.NoError(t, err)
210 f, err := clientFS.Create("/repo/not-empty")
211 require.NoError(t, err)
212 require.NoError(t, f.Close())
213
214 err = git.ShallowCloneRepo(context.Background(), t.Logf, git.CloneRepoOptions{
215 Path: "/repo",
216 RepoURL: srv.URL,
217 Storage: clientFS,
218 RepoAuth: &githttp.BasicAuth{
219 Username: "test",
220 Password: "test",
221 },
222 })
223 require.Error(t, err)
224 })
225 t.Run("OK", func(t *testing.T) {
226 // 2024/08/01 13:22:08 unsupported capability: shallow
227 // clone "http://127.0.0.1:41499": unexpected client error: unexpected requesting "http://127.0.0.1:41499/git-upload-pack" status code: 500
228 t.Skip("The gittest server doesn't support shallow cloning, skip for now...")
229
230 t.Parallel()
231 srvFS := memfs.New()
232 _ = gittest.NewRepo(t, srvFS,
233 gittest.Commit(t, "README.md", "Hello, world!", "Many wow!"),
234 gittest.Commit(t, "foo", "bar!", "Such commit!"),
235 gittest.Commit(t, "baz", "qux", "V nice!"),
236 )
237 authMW := mwtest.BasicAuthMW("test", "test")
238 srv := httptest.NewServer(authMW(gittest.NewServer(srvFS)))
239
240 clientFS := memfs.New()
241
242 err := git.ShallowCloneRepo(context.Background(), t.Logf, git.CloneRepoOptions{
243 Path: "/repo",
244 RepoURL: srv.URL,
245 Storage: clientFS,
246 RepoAuth: &githttp.BasicAuth{
247 Username: "test",
248 Password: "test",
249 },

Callers

nothing calls this directly

Calls 10

NewRepoFunction · 0.92
CommitFunction · 0.92
BasicAuthMWFunction · 0.92
NewServerFunction · 0.92
ShallowCloneRepoFunction · 0.92
CloseMethod · 0.80
ErrorMethod · 0.80
JoinMethod · 0.80
MkdirAllMethod · 0.65
StatMethod · 0.65

Tested by

no test coverage detected