UNPKG

staticql

Version:

Type-safe query engine for static content including Markdown, YAML, JSON, and more.

24 lines (23 loc) 774 B
import { execSync } from "child_process"; export class GitDiffProvider { constructor(baseDir) { this.baseDir = baseDir; } async diffLines(baseRef, headRef) { const output = execSync(`git fetch origin main && git diff --name-status --diff-filter=ADM --no-renames ${baseRef}..${headRef}`, { encoding: "utf8", cwd: this.baseDir }); return output .trim() .split(/\r?\n/) .filter(Boolean) .map((line) => { const [status, path] = line.split(/\t/); return { status: status, path }; }); } async gitShow(rev, filePath) { return execSync(`git show ${rev}:${filePath}`, { encoding: "utf8", cwd: this.baseDir, }); } }