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

Method Remove

pkg/worktree/worktree.go:303–313  ·  view source on GitHub ↗

Remove deletes the worktree's directory and its branch, discarding any uncommitted changes, untracked files, and commits. Callers decide when removal is appropriate (e.g. only for worktrees they created, never pre-existing ones).

(ctx context.Context)

Source from the content-addressed store, hash-verified

301// removal is appropriate (e.g. only for worktrees they created, never
302// pre-existing ones).
303func (wt *Worktree) Remove(ctx context.Context) error {
304 if err := git(ctx, wt.SourceDir, "worktree", "remove", "--force", wt.Dir); err != nil {
305 return fmt.Errorf("removing git worktree: %w", err)
306 }
307 // The branch can only be deleted once the worktree no longer occupies it;
308 // -D discards unmerged commits, which is the intended "remove and forget".
309 if err := git(ctx, wt.SourceDir, "branch", "-D", wt.Branch); err != nil {
310 return fmt.Errorf("deleting worktree branch: %w", err)
311 }
312 return nil
313}
314
315// validateName rejects names that would escape the worktrees directory or
316// produce an invalid git branch. Names must be a single path segment made of

Callers 15

writeJSONFunction · 0.45
dialFunction · 0.45
PutMethod · 0.45
DeleteMethod · 0.45
rotateMethod · 0.45
TestRemoveFunction · 0.45
pullDockerModelIfNeededFunction · 0.45
migrateFromLegacyMethod · 0.45
StopMethod · 0.45
listenUnixFunction · 0.45
DeleteArtifactMethod · 0.45

Calls 1

gitFunction · 0.85