(t *testing.T)
| 99 | } |
| 100 | |
| 101 | func TestCreateWorktree(t *testing.T) { |
| 102 | t.Run("creates worktree and branch", func(t *testing.T) { |
| 103 | dir := initTestRepo(t) |
| 104 | wtPath := filepath.Join(dir, "worktrees", "test-prd") |
| 105 | |
| 106 | err := CreateWorktree(dir, wtPath, "chief/test-prd") |
| 107 | if err != nil { |
| 108 | t.Fatalf("CreateWorktree() error = %v", err) |
| 109 | } |
| 110 | |
| 111 | // Verify worktree exists and is on the right branch |
| 112 | branch, err := GetCurrentBranch(wtPath) |
| 113 | if err != nil { |
| 114 | t.Fatalf("GetCurrentBranch() error = %v", err) |
| 115 | } |
| 116 | if branch != "chief/test-prd" { |
| 117 | t.Errorf("branch = %q, want %q", branch, "chief/test-prd") |
| 118 | } |
| 119 | }) |
| 120 | |
| 121 | t.Run("reuses existing valid worktree", func(t *testing.T) { |
| 122 | dir := initTestRepo(t) |
| 123 | wtPath := filepath.Join(dir, "worktrees", "test-prd") |
| 124 | |
| 125 | // Create worktree first time |
| 126 | if err := CreateWorktree(dir, wtPath, "chief/test-prd"); err != nil { |
| 127 | t.Fatalf("first CreateWorktree() error = %v", err) |
| 128 | } |
| 129 | |
| 130 | // Create a file in the worktree to verify it's reused (not recreated) |
| 131 | marker := filepath.Join(wtPath, "marker.txt") |
| 132 | if err := os.WriteFile(marker, []byte("marker"), 0644); err != nil { |
| 133 | t.Fatalf("failed to create marker: %v", err) |
| 134 | } |
| 135 | |
| 136 | // Create again - should reuse |
| 137 | if err := CreateWorktree(dir, wtPath, "chief/test-prd"); err != nil { |
| 138 | t.Fatalf("second CreateWorktree() error = %v", err) |
| 139 | } |
| 140 | |
| 141 | // Marker should still exist |
| 142 | if _, err := os.Stat(marker); err != nil { |
| 143 | t.Error("marker file was removed - worktree was not reused") |
| 144 | } |
| 145 | }) |
| 146 | |
| 147 | t.Run("recreates stale worktree with wrong branch", func(t *testing.T) { |
| 148 | dir := initTestRepo(t) |
| 149 | wtPath := filepath.Join(dir, "worktrees", "test-prd") |
| 150 | |
| 151 | // Create worktree with one branch |
| 152 | if err := CreateWorktree(dir, wtPath, "chief/branch-a"); err != nil { |
| 153 | t.Fatalf("first CreateWorktree() error = %v", err) |
| 154 | } |
| 155 | |
| 156 | // Create again with a different branch - should remove and recreate |
| 157 | if err := CreateWorktree(dir, wtPath, "chief/branch-b"); err != nil { |
| 158 | t.Fatalf("second CreateWorktree() error = %v", err) |
nothing calls this directly
no test coverage detected