gitKept

tcmts.cli.mirror.gitKept · #xdrmlq7s · term · runs on the server

uses node:child_process

The files git keeps under dir (tracked, or new and not ignored), as absolute paths: undefined outside a repository.

import { spawnSync } from "node:child_process";
import path from "node:path";

export function gitKept(dir: string): Set<string> | undefined {
  const r = spawnSync("git", ["-C", dir, "ls-files", "--cached", "--others", "--exclude-standard", "-z"], { encoding: "utf8" });
  if (r.status !== 0) return undefined;
  return new Set(r.stdout.split("\0").filter(Boolean).map((f) => path.resolve(dir, f)));
}

used by