Files
ai-codebase-doc-drift-detector/src/git-tracker.ts
T
2026-06-17 12:27:02 +00:00

44 lines
1.1 KiB
TypeScript

/**
* Git Tracker — discover changed files via git.
*/
import { execSync } from 'node:child_process';
export function getGitRoot(cwd: string): string | null {
try {
return execSync('git rev-parse --show-toplevel', { cwd, encoding: 'utf-8' }).trim();
} catch {
return null;
}
}
export function getChangedFiles(cwd: string, sinceRef?: string): string[] {
try {
const cmd = sinceRef
? `git diff --name-only ${sinceRef} --`
: 'git diff --name-only HEAD~1 --';
const out = execSync(cmd, { cwd, encoding: 'utf-8' }).trim();
if (!out) return [];
return out.split('\n').filter(Boolean);
} catch {
return [];
}
}
export function getAllTrackedFiles(cwd: string): string[] {
try {
const out = execSync('git ls-files', { cwd, encoding: 'utf-8' }).trim();
if (!out) return [];
return out.split('\n').filter(Boolean);
} catch {
return [];
}
}
export function getLastCommitDate(cwd: string): string | null {
try {
return execSync('git log -1 --format=%cI', { cwd, encoding: 'utf-8' }).trim();
} catch {
return null;
}
}