MCPcopy Create free account
hub / github.com/cli/cli / TestParseWorktrees

Function TestParseWorktrees

git/client_test.go:2291–2382  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

2289}
2290
2291func TestParseWorktrees(t *testing.T) {
2292 tests := []struct {
2293 name string
2294 out string
2295 want []Worktree
2296 }{
2297 {
2298 name: "empty output",
2299 out: "",
2300 want: nil,
2301 },
2302 {
2303 name: "single worktree",
2304 out: heredoc.Doc(`
2305 worktree /path/to/main
2306 HEAD abc123
2307 branch refs/heads/main
2308 `),
2309 want: []Worktree{
2310 {Path: "/path/to/main", Ref: "refs/heads/main"},
2311 },
2312 },
2313 {
2314 name: "multiple worktrees",
2315 out: heredoc.Doc(`
2316 worktree /path/to/main
2317 HEAD abc123
2318 branch refs/heads/main
2319
2320 worktree /path/to/feature-wt
2321 HEAD def456
2322 branch refs/heads/feature
2323 `),
2324 want: []Worktree{
2325 {Path: "/path/to/main", Ref: "refs/heads/main"},
2326 {Path: "/path/to/feature-wt", Ref: "refs/heads/feature"},
2327 },
2328 },
2329 {
2330 name: "detached HEAD has no branch",
2331 out: heredoc.Doc(`
2332 worktree /path/to/main
2333 HEAD abc123
2334 branch refs/heads/main
2335
2336 worktree /path/to/detached
2337 HEAD def456
2338 detached
2339 `),
2340 want: []Worktree{
2341 {Path: "/path/to/main", Ref: "refs/heads/main"},
2342 {Path: "/path/to/detached", Ref: ""},
2343 },
2344 },
2345 {
2346 name: "no trailing blank line",
2347 out: "worktree /path/to/main\nHEAD abc123\nbranch refs/heads/main",
2348 want: []Worktree{

Callers

nothing calls this directly

Calls 3

parseWorktreesFunction · 0.85
EqualMethod · 0.80
RunMethod · 0.65

Tested by

no test coverage detected