41 lines
1.2 KiB
JavaScript
41 lines
1.2 KiB
JavaScript
#!/usr/bin/env node
|
|
|
|
import { spawnSync } from 'node:child_process';
|
|
|
|
import { deriveHistoryBoundary } from './gate-history.mjs';
|
|
|
|
const candidateKind = process.argv[2];
|
|
const root = process.cwd();
|
|
const boundary = deriveHistoryBoundary(root);
|
|
|
|
function revParse(revision) {
|
|
const result = spawnSync('git', ['rev-parse', revision], {
|
|
cwd: root,
|
|
encoding: 'utf8',
|
|
});
|
|
if (result.status !== 0) {
|
|
process.stderr.write(`history boundary control could not resolve ${revision}\n`);
|
|
process.exit(2);
|
|
}
|
|
return result.stdout.trim();
|
|
}
|
|
|
|
const candidates = {
|
|
head: revParse('HEAD'),
|
|
parent: revParse('HEAD^'),
|
|
introduction: boundary.introductionCommit,
|
|
};
|
|
if (!Object.hasOwn(candidates, candidateKind)) {
|
|
process.stderr.write(`unknown history boundary candidate ${String(candidateKind)}\n`);
|
|
process.exit(2);
|
|
}
|
|
const candidate = candidates[candidateKind];
|
|
if (candidate === boundary.activationCommit) {
|
|
process.stdout.write(`history boundary candidate ${candidateKind} matched derived activation\n`);
|
|
process.exit(0);
|
|
}
|
|
process.stderr.write(
|
|
`history boundary candidate ${candidateKind} rejected: derived activation is provider target merge-base\n`,
|
|
);
|
|
process.exit(1);
|