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

Function TestParseWorktrees

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

Source from the content-addressed store, hash-verified

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

Callers

nothing calls this directly

Calls 3

parseWorktreesFunction · 0.85
EqualMethod · 0.80
RunMethod · 0.65

Tested by

no test coverage detected