MCPcopy
hub / github.com/docker/docker-agent / cleanupWorktree

Method cleanupWorktree

cmd/root/run.go:630–650  ·  view source on GitHub ↗

cleanupWorktree removes a worktree created for an interactive run once it ends. A clean worktree (no uncommitted changes, untracked files, or new commits) is removed automatically. A dirty one is kept unless the user explicitly asks to remove it, so work is never discarded silently. Failures are rep

(ctx context.Context, out *cli.Printer, wt *worktree.Worktree)

Source from the content-addressed store, hash-verified

628// Failures are reported but never abort the command — the run already
629// succeeded.
630func (f *runExecFlags) cleanupWorktree(ctx context.Context, out *cli.Printer, wt *worktree.Worktree) {
631 st, err := wt.Status(ctx)
632 if err != nil {
633 out.Println("Could not inspect git worktree " + wt.Dir + ": " + err.Error())
634 out.Println("Leaving it in place. Remove it manually with: git -C " + wt.SourceDir + " worktree remove " + wt.Dir)
635 return
636 }
637
638 if st.IsDirty() {
639 if !promptRemoveDirtyWorktree(ctx, out, wt, st) {
640 out.Println("Keeping git worktree " + wt.Dir + " (branch " + wt.Branch + ").")
641 return
642 }
643 }
644
645 if err := wt.Remove(ctx); err != nil {
646 out.Println("Failed to remove git worktree " + wt.Dir + ": " + err.Error())
647 return
648 }
649 out.Println("Removed git worktree " + wt.Dir + " (branch " + wt.Branch + ").")
650}
651
652// promptRemoveDirtyWorktree asks the user whether to discard a worktree that
653// still holds work. It defaults to keeping (returns false) on any non-yes

Calls 6

StatusMethod · 0.80
PrintlnMethod · 0.80
IsDirtyMethod · 0.80
ErrorMethod · 0.45
RemoveMethod · 0.45