MCPcopy Create free account
hub / github.com/MiniCodeMonkey/chief / initTestRepo

Function initTestRepo

internal/git/worktree_test.go:12–47  ·  view source on GitHub ↗

initTestRepo creates a temporary git repository with an initial commit and returns its path.

(t *testing.T)

Source from the content-addressed store, hash-verified

10
11// initTestRepo creates a temporary git repository with an initial commit and returns its path.
12func initTestRepo(t *testing.T) string {
13 t.Helper()
14 dir := t.TempDir()
15
16 cmds := [][]string{
17 {"git", "init"},
18 {"git", "config", "user.email", "test@test.com"},
19 {"git", "config", "user.name", "Test"},
20 {"git", "checkout", "-b", "main"},
21 }
22 for _, args := range cmds {
23 cmd := exec.Command(args[0], args[1:]...)
24 cmd.Dir = dir
25 if out, err := cmd.CombinedOutput(); err != nil {
26 t.Fatalf("setup command %v failed: %s", args, string(out))
27 }
28 }
29
30 // Create an initial commit so branches can be created
31 readme := filepath.Join(dir, "README.md")
32 if err := os.WriteFile(readme, []byte("# Test\n"), 0644); err != nil {
33 t.Fatalf("failed to create README: %v", err)
34 }
35 cmd := exec.Command("git", "add", ".")
36 cmd.Dir = dir
37 if out, err := cmd.CombinedOutput(); err != nil {
38 t.Fatalf("git add failed: %s", string(out))
39 }
40 cmd = exec.Command("git", "commit", "-m", "initial commit")
41 cmd.Dir = dir
42 if out, err := cmd.CombinedOutput(); err != nil {
43 t.Fatalf("git commit failed: %s", string(out))
44 }
45
46 return dir
47}
48
49func TestGetDefaultBranch(t *testing.T) {
50 t.Run("detects main branch", func(t *testing.T) {

Callers 9

TestPushBranchFunction · 0.85
TestDeleteBranchFunction · 0.85
TestGetDefaultBranchFunction · 0.85
TestCreateWorktreeFunction · 0.85
TestRemoveWorktreeFunction · 0.85
TestListWorktreesFunction · 0.85
TestIsWorktreeFunction · 0.85
TestPruneWorktreesFunction · 0.85
TestMergeBranchFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected