MCPcopy Index your code
hub / github.com/jetify-com/devbox / setupLocalGitRepo

Function setupLocalGitRepo

internal/plugin/git_test.go:408–449  ·  view source on GitHub ↗

setupLocalGitRepo creates a temporary bare git repo with a plugin.json file. Returns the file:// URL to the repo.

(t *testing.T, content string)

Source from the content-addressed store, hash-verified

406// setupLocalGitRepo creates a temporary bare git repo with a plugin.json file.
407// Returns the file:// URL to the repo.
408func setupLocalGitRepo(t *testing.T, content string) string {
409 t.Helper()
410
411 if _, err := exec.LookPath("git"); err != nil {
412 t.Skip("skipping: git not found in PATH")
413 }
414
415 // Create a working repo, commit a file, then clone it as bare.
416 workDir := t.TempDir()
417 runGit := func(args ...string) {
418 t.Helper()
419 cmd := exec.Command("git", args...)
420 cmd.Dir = workDir
421 cmd.Env = append(os.Environ(),
422 "GIT_AUTHOR_NAME=test",
423 "GIT_AUTHOR_EMAIL=test@test.com",
424 "GIT_COMMITTER_NAME=test",
425 "GIT_COMMITTER_EMAIL=test@test.com",
426 )
427 out, err := cmd.CombinedOutput()
428 if err != nil {
429 t.Fatalf("git %v failed: %v\n%s", args, err, out)
430 }
431 }
432
433 runGit("init")
434 runGit("checkout", "-b", "main")
435 if err := os.WriteFile(filepath.Join(workDir, "plugin.json"), []byte(content), 0o644); err != nil {
436 t.Fatal(err)
437 }
438 runGit("add", "plugin.json")
439 runGit("commit", "-m", "init")
440
441 // Clone to bare repo so file:// clone works cleanly.
442 bareDir := t.TempDir()
443 cmd := exec.Command("git", "clone", "--bare", workDir, bareDir)
444 if out, err := cmd.CombinedOutput(); err != nil {
445 t.Fatalf("bare clone failed: %v\n%s", err, out)
446 }
447
448 return "file://" + bareDir
449}
450
451func TestGitPluginFileContentCache(t *testing.T) {
452 // Clear the git cache before and after the test to avoid pollution.

Calls 2

CommandMethod · 0.80
CombinedOutputMethod · 0.80

Tested by

no test coverage detected