MCPcopy Index your code
hub / github.com/docker/docker-agent / promptRemoveDirtyWorktree

Function promptRemoveDirtyWorktree

cmd/root/run.go:655–676  ·  view source on GitHub ↗

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)

Source from the content-addressed store, hash-verified

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.
655func 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

Callers 1

cleanupWorktreeMethod · 0.85

Calls 2

ReadLineFunction · 0.92
PrintlnMethod · 0.80

Tested by

no test coverage detected