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

72.72% Statements 8/11
100% Branches 2/2
25% Functions 1/4
80% Lines 8/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        1x     1x 3x 3x   3x 3x             1x       1x      
import { assertNotFlagLike } from "../../shared/adapters/exec.ts";
import { git } from "../../shared/adapters/git.ts";
import { ExpectedError } from "../../shared/errors.ts";
 
export const currentBranch = (): string => git("rev-parse", "--abbrev-ref", "HEAD");
 
/** Validate the environment-provided branch before passing it as a Git argument. */
export const push = (branch: string): void => {
    try {
        git("push", "-u", "origin", assertNotFlagLike(branch, "branch"));
    } catch (error) {
        const stderr = (error as { stderr?: Buffer | string }).stderr?.toString().trim();
        throw new ExpectedError(
            "Push rejected — ensure the code passes the push requirements (branch name, lint, test, typecheck) before shipping." +
                (stderr ? `\n${stderr}` : ""),
        );
    }
};
 
export const checkoutMaster = (): void => {
    git("checkout", "master");
};
 
export const pullMaster = (): void => {
    git("pull", "origin", "master");
};