(t *testing.T)
| 172 | } |
| 173 | |
| 174 | func TestWorktreeCheckoutCommands(t *testing.T) { |
| 175 | tests := []struct { |
| 176 | name string |
| 177 | target WorktreeTarget |
| 178 | branchExists bool |
| 179 | wantCommands [][]string |
| 180 | }{ |
| 181 | { |
| 182 | name: "fresh target with existing branch", |
| 183 | target: WorktreeTarget{Path: "/path/to/wt"}, |
| 184 | branchExists: true, |
| 185 | wantCommands: [][]string{{"worktree", "add", "--", "/path/to/wt", "feature"}}, |
| 186 | }, |
| 187 | { |
| 188 | name: "fresh target with new branch", |
| 189 | target: WorktreeTarget{Path: "/path/to/wt"}, |
| 190 | wantCommands: [][]string{{"worktree", "add", "--track", "-b", "feature", "--", "/path/to/wt", "origin/feature"}}, |
| 191 | }, |
| 192 | { |
| 193 | name: "reused target with existing branch", |
| 194 | target: WorktreeTarget{Path: "/path/to/wt", Reuse: true}, |
| 195 | branchExists: true, |
| 196 | wantCommands: [][]string{{"-C", "/path/to/wt", "checkout", "feature"}}, |
| 197 | }, |
| 198 | { |
| 199 | name: "reused target with new branch", |
| 200 | target: WorktreeTarget{Path: "/path/to/wt", Reuse: true}, |
| 201 | wantCommands: [][]string{{"-C", "/path/to/wt", "checkout", "-b", "feature", "--track", "origin/feature"}}, |
| 202 | }, |
| 203 | } |
| 204 | |
| 205 | for _, tt := range tests { |
| 206 | t.Run(tt.name, func(t *testing.T) { |
| 207 | cs, teardown := run.Stub() |
| 208 | defer teardown(t) |
| 209 | exitCode := 1 |
| 210 | if tt.branchExists { |
| 211 | exitCode = 0 |
| 212 | } |
| 213 | cs.Register(`git rev-parse --verify refs/heads/feature`, exitCode, "") |
| 214 | |
| 215 | client := &git.Client{GitPath: "/some/path/git"} |
| 216 | commands, branchExists := WorktreeCheckoutCommands(client, tt.target, "feature", "origin/feature") |
| 217 | |
| 218 | assert.Equal(t, tt.branchExists, branchExists) |
| 219 | assert.Equal(t, tt.wantCommands, commands) |
| 220 | }) |
| 221 | } |
| 222 | } |
nothing calls this directly
no test coverage detected