MCPcopy Create free account
hub / github.com/GongShichen/LuminaCode / RemoveWorktree

Function RemoveWorktree

agent/worktree.go:63–88  ·  view source on GitHub ↗
(ctx context.Context, path string)

Source from the content-addressed store, hash-verified

61 result.WorktreePath = path
62 return result, nil
63}
64
65func RemoveWorktree(ctx context.Context, path string) error {
66 if path == "" {
67 return nil
68 }
69 repoRoot := FindGitRoot(path)
70 if repoRoot == "" {
71 _ = os.RemoveAll(path)
72 return nil
73 }
74 cmdCtx, cancel := context.WithTimeout(ctx, 30*time.Second)
75 defer cancel()
76 cmd := exec.CommandContext(cmdCtx, "git", "worktree", "remove", "--force", path)
77 cmd.Dir = repoRoot
78 if out, err := cmd.CombinedOutput(); err != nil {
79 _ = os.RemoveAll(path)
80 _ = out
81 return nil
82 }
83 pruneCtx, pruneCancel := context.WithTimeout(ctx, 10*time.Second)
84 defer pruneCancel()
85 prune := exec.CommandContext(pruneCtx, "git", "worktree", "prune")
86 prune.Dir = repoRoot
87 _ = prune.Run()
88 _ = os.RemoveAll(path)
89 return nil
90}
91

Calls 2

FindGitRootFunction · 0.85
RunMethod · 0.65