All files / infrastructure/scripts/src/invariants/adapters git.ts

0% Statements 0/12
0% Branches 0/4
0% Functions 0/2
0% Lines 0/10

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31                                                             
import { assertNotFlagLike, capture } from "../../shared/adapters/exec.ts";
import { at } from "../../shared/adapters/git.ts";
import { ExpectedError } from "../../shared/errors.ts";
 
/** A missing ref would otherwise read as "every file is new" and skip the version check silently. */
export const assertCommit = (ref: string): string => {
    const { status } = capture("git", [
        "-C",
        at(),
        "rev-parse",
        "--verify",
        "--quiet",
        `${assertNotFlagLike(ref, "--base")}^{commit}`,
    ]);
    if (status !== 0) throw new ExpectedError(`--base=${ref} is not a commit in this repository.`);
 
    return ref;
};
 
/** The manifest at `ref`, or undefined when the file did not exist there. */
export const manifestAt = (ref: string, path: string): unknown => {
    const { status, stdout } = capture("git", ["-C", at(), "show", `${ref}:${path}`]);
    if (status !== 0) return undefined;
 
    try {
        return JSON.parse(stdout) as unknown;
    } catch {
        return undefined;
    }
};