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

100% Statements 14/14
100% Branches 0/0
100% Functions 7/7
100% Lines 14/14

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        1x 5x   1x 2x   1x 2x   1x 1x   1x 1x   1x 1x     1x 1x  
import { assertNotFlagLike } from "../../shared/adapters/exec.ts";
import { at, git } from "../../shared/adapters/git.ts";
 
/** Validate refs before joining them into `base..head`, or a leading `-` can evade the check. */
const range = (base: string, head: string): string =>
    `${assertNotFlagLike(base, "base")}..${assertNotFlagLike(head, "head")}`;
 
export const mergeBase = (ref: string): string =>
    git("merge-base", "HEAD", assertNotFlagLike(ref, "ref"));
 
export const changedFiles = (base: string, head: string): string[] =>
    git("diff", "--name-only", range(base, head)).split("\n").filter(Boolean);
 
export const diffNumstat = (base: string, head: string, root: string): string[] =>
    git("diff", "--numstat", range(base, head), "--", at(root)).split("\n").filter(Boolean);
 
export const diffNameStatus = (base: string, head: string, root: string): string[] =>
    git("diff", "--name-status", range(base, head), "--", at(root)).split("\n").filter(Boolean);
 
export const diffText = (base: string, head: string, root: string): string =>
    git("diff", range(base, head), "--", at(root));
 
/** `:(glob)` enables `**` for this pathspec; empty output means the root has no markdown history. */
export const lastMdCommitEpochSeconds = (root: string): string =>
    git("log", "-1", "--format=%ct", "--", `:(glob)${at(root)}/**/*.md`);