MCPcopy
hub / github.com/garrytan/gstack / pruneStale

Method pruneStale

lib/worktree.ts:249–273  ·  view source on GitHub ↗

Remove worktrees from previous runs that weren't cleaned up.

()

Source from the content-addressed store, hash-verified

247
248 /** Remove worktrees from previous runs that weren't cleaned up. */
249 pruneStale(): void {
250 try {
251 git(['worktree', 'prune'], this.repoRoot, true);
252
253 const worktreeBase = path.join(this.repoRoot, '.gstack-worktrees');
254 if (!fs.existsSync(worktreeBase)) return;
255
256 for (const entry of fs.readdirSync(worktreeBase)) {
257 // Don't prune our own run
258 if (entry === this.runId) continue;
259
260 const entryPath = path.join(worktreeBase, entry);
261 try {
262 // Skip recent worktrees (< 1 hour old) to avoid killing
263 // worktrees from concurrent test runs still in progress
264 const stat = fs.statSync(entryPath);
265 const ageMs = Date.now() - stat.mtimeMs;
266 if (ageMs < 3600_000) continue;
267 fs.rmSync(entryPath, { recursive: true, force: true });
268 } catch { /* non-fatal */ }
269 }
270 } catch {
271 process.stderr.write(' WORKTREE: prune failed (non-fatal)\n');
272 }
273 }
274
275 /** Print harvest report summary. */
276 printReport(): void {

Callers 2

worktree.test.tsFile · 0.80
getWorktreeManagerFunction · 0.80

Calls 1

gitFunction · 0.70

Tested by

no test coverage detected