mirror of
https://github.com/PR0M3TH3AN/TORCH.git
synced 2026-11-08 22:02:12 +00:00
Create safe fleet worktrees
This commit is contained in:
1 parent
b609ae44ce
commit
5085bc722a
9 files changed
+376
-9
No files matched your search
@@ -0,0 +1,22 @@
|
||||
import { execFileSync } from 'node:child_process';
|
||||
import { existsSync } from 'node:fs';
|
||||
|
||||
function git(root, args) {
|
||||
try {
|
||||
return execFileSync('git', ['-C', root, ...args], {
|
||||
encoding: 'utf8', stdio: ['ignore', 'pipe', 'ignore'],
|
||||
}).trim();
|
||||
} catch { return ''; }
|
||||
}
|
||||
|
||||
export function inspectManagedWorktree(root, entry, mainBranch) {
|
||||
if (!existsSync(entry.path)) return { ...entry, safeToRemove: false, problems: ['worktree-missing'] };
|
||||
const problems = [];
|
||||
const actualBranch = git(entry.path, ['branch', '--show-current']);
|
||||
if (actualBranch !== entry.branch) problems.push(`branch-mismatch:${actualBranch || 'detached'}`);
|
||||
const status = git(entry.path, ['status', '--porcelain=v1', '--untracked-files=all']);
|
||||
if (status) problems.push('worktree-dirty');
|
||||
const ahead = Number(git(root, ['rev-list', '--count', `${mainBranch}..${entry.branch}`]) || 0);
|
||||
if (ahead > 0) problems.push(`unique-commits:${ahead}`);
|
||||
return { ...entry, actualBranch, ahead, safeToRemove: problems.length === 0, problems };
|
||||
}
|
||||
Reference in new issue
Block a user