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

Function TestGetDefaultBranch

internal/git/worktree_test.go:49–99  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

47}
48
49func TestGetDefaultBranch(t *testing.T) {
50 t.Run("detects main branch", func(t *testing.T) {
51 dir := initTestRepo(t)
52 branch, err := GetDefaultBranch(dir)
53 if err != nil {
54 t.Fatalf("GetDefaultBranch() error = %v", err)
55 }
56 if branch != "main" {
57 t.Errorf("GetDefaultBranch() = %q, want %q", branch, "main")
58 }
59 })
60
61 t.Run("detects master branch", func(t *testing.T) {
62 dir := t.TempDir()
63 cmds := [][]string{
64 {"git", "init"},
65 {"git", "config", "user.email", "test@test.com"},
66 {"git", "config", "user.name", "Test"},
67 {"git", "checkout", "-b", "master"},
68 }
69 for _, args := range cmds {
70 cmd := exec.Command(args[0], args[1:]...)
71 cmd.Dir = dir
72 if out, err := cmd.CombinedOutput(); err != nil {
73 t.Fatalf("setup command %v failed: %s", args, string(out))
74 }
75 }
76 readme := filepath.Join(dir, "README.md")
77 if err := os.WriteFile(readme, []byte("# Test\n"), 0644); err != nil {
78 t.Fatalf("failed to create README: %v", err)
79 }
80 cmd := exec.Command("git", "add", ".")
81 cmd.Dir = dir
82 if out, err := cmd.CombinedOutput(); err != nil {
83 t.Fatalf("git add failed: %s", string(out))
84 }
85 cmd = exec.Command("git", "commit", "-m", "initial commit")
86 cmd.Dir = dir
87 if out, err := cmd.CombinedOutput(); err != nil {
88 t.Fatalf("git commit failed: %s", string(out))
89 }
90
91 branch, err := GetDefaultBranch(dir)
92 if err != nil {
93 t.Fatalf("GetDefaultBranch() error = %v", err)
94 }
95 if branch != "master" {
96 t.Errorf("GetDefaultBranch() = %q, want %q", branch, "master")
97 }
98 })
99}
100
101func TestCreateWorktree(t *testing.T) {
102 t.Run("creates worktree and branch", func(t *testing.T) {

Callers

nothing calls this directly

Calls 3

initTestRepoFunction · 0.85
GetDefaultBranchFunction · 0.85
RunMethod · 0.80

Tested by

no test coverage detected