Files
orca/config/scripts/worktree-storage/local-repository-worktrees.mjs
T
Neil 9bd6272fdf refactor(tooling): organize build, CI, and test owners (#38130)
* refactor(tooling): organize test runtime and maintenance owners

* test(tooling): preserve relocated runtime fixture dependency edges

* refactor(tooling): preserve xterm routing owner checks

* ci(tooling): include routing owner in sparse checkout

* test(tooling): preserve copied workflow dependency closures

* fix(tooling): normalize hashed JSON assets in release parity

* fix(tooling): distinguish asset aliases from literal references

* fix(tooling): frame normalized asset reference payloads

* fix(tooling): normalize decoded JSON asset references

* refactor(tooling): organize build, CI and release owners

* fix(tooling): align moved generator and workflow path contracts

* fix(tooling): update generated plugin bundle owner banners

* test(tooling): create relocated mobile verifier fixture directories

* test(tooling): copy headless detector dependency closure

* test(tooling): align native batch policy fixtures with owner path

* fix(tooling): link moved reliability command to historical evidence

* fix(tooling): preserve nested sandbox owners and canonical guide source

* fix(tooling): target release version owners in checkout fixture
2026-11-04 21:08:19 -08:00

57 lines
1.7 KiB
JavaScript

import { realpath } from 'node:fs/promises'
import { resolve } from 'node:path'
import { runProcess } from '@orca/process-host'
import { decodeGitCQuotedPath } from '../../../src/shared/git/paths/git-cquoted-path.ts'
async function git(repoRoot, args) {
const result = await runProcess({
program: 'git',
args,
cwd: repoRoot,
timeoutMs: 30_000,
maxOutputBytes: 4 * 1024 * 1024,
terminationBarrier: true
})
if (result.code !== 0 || result.timedOut) {
throw new Error('Could not read the local Git repository')
}
return result.stdout
}
export async function localRepositoryWorktrees(repoRoot) {
const common = (await git(repoRoot, ['rev-parse', '--git-common-dir'])).replace(
process.platform === 'win32' ? /\r?\n$/ : /\n$/,
''
)
if (!common || common.includes('\n')) {
throw new Error('Unrecognised Git common directory')
}
const output = await git(repoRoot, [
'-c',
'core.quotePath=false',
'worktree',
'list',
'--porcelain'
])
const worktrees = []
for (const block of output.split(/\r?\n\r?\n/)) {
const lines = block.split(/\r?\n/).filter(Boolean)
if (lines.length === 0) {
continue
}
if (
lines.some(
(line) =>
!/^(worktree |HEAD |branch |bare$|detached$|locked(?: |$)|prunable(?: |$))/.test(line)
)
) {
throw new Error('Ambiguous worktree listing; refusing cleanup')
}
const field = lines.find((line) => line.startsWith('worktree '))
if (field && !lines.includes('bare')) {
worktrees.push(decodeGitCQuotedPath(field.slice(9)))
}
}
return { commonDirectory: await realpath(resolve(repoRoot, common)), worktrees }
}