promptRemoveDirtyWorktree asks the user whether to discard a worktree that still holds work. It defaults to keeping (returns false) on any non-yes answer or read error, so uncommitted work is never lost by accident.
(ctx context.Context, out *cli.Printer, wt *worktree.Worktree, st worktree.Status)
| 653 | // still holds work. It defaults to keeping (returns false) on any non-yes |
| 654 | // answer or read error, so uncommitted work is never lost by accident. |
| 655 | func promptRemoveDirtyWorktree(ctx context.Context, out *cli.Printer, wt *worktree.Worktree, st worktree.Status) bool { |
| 656 | var held []string |
| 657 | if st.Modified { |
| 658 | held = append(held, "uncommitted changes") |
| 659 | } |
| 660 | if st.Untracked { |
| 661 | held = append(held, "untracked files") |
| 662 | } |
| 663 | if st.NewCommits { |
| 664 | held = append(held, "new commits") |
| 665 | } |
| 666 | |
| 667 | out.Println("\nThe git worktree " + wt.Dir + " (branch " + wt.Branch + ") still has " + strings.Join(held, ", ") + ".") |
| 668 | out.Println("Remove it and discard this work? Keeping preserves the directory and branch so you can return later. (y/N):") |
| 669 | |
| 670 | response, err := input.ReadLine(ctx, os.Stdin) |
| 671 | if err != nil { |
| 672 | return false |
| 673 | } |
| 674 | response = strings.TrimSpace(strings.ToLower(response)) |
| 675 | return response == "y" || response == "yes" |
| 676 | } |
| 677 | |
| 678 | // dispatchWorktreeCreate fires the worktree_create hooks of the agent the |
| 679 | // run targets, just after the worktree is created and before the session |
no test coverage detected