All files / infrastructure/scripts/src/worktree/domain worktree.ts

100% Statements 10/10
85.71% Branches 6/7
100% Functions 5/5
100% Lines 10/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            2x 5x   15x       15x   2x 5x 5x     2x 2x 2x    
interface Worktree {
    path: string;
    branch: string | undefined;
}
 
/** `git worktree list --porcelain` lists the main checkout first, then every linked one. */
export const parseWorktrees = (porcelain: string): Worktree[] =>
    porcelain
        .split(/\n\s*\n/)
        .map((entry) => ({
            path: /^worktree (.+)$/m.exec(entry)?.[1],
            branch: /^branch refs\/heads\/(.+)$/m.exec(entry)?.[1],
        }))
        .filter((tree): tree is Worktree => tree.path !== undefined);
 
export const isEnvFile = (path: string): boolean => {
    const name = path.split("/").at(-1) ?? "";
    return !path.includes("node_modules/") && (name === ".env" || name.startsWith(".env."));
};
 
export const preparedLine = (path: string, copied: string[]): string => {
    const env = copied.length > 0 ? `copied ${copied.join(", ")}` : "no env files to copy";
    return `${path}: installed, ${env}`;
};