Files
renovate/tools/check/git.ts
T
Sergei Zharinov 015ce80baa chore(tools): Add check script (#40185)
* base: pile foundation

* refactor(tools): Split check.ts into modular components

- Separate files for types, coverage, git, tui, execution, test-filter
- Fix signal handler timing (register at module load)
- Export getMatchingShards/getTestPatternsForShards from test-shards.ts
2026-01-23 01:12:10 +00:00

51 lines
1.2 KiB
TypeScript

import { execa } from 'execa';
async function getGitFiles(args: string[]): Promise<string[]> {
try {
const result = await execa('git', args);
return result.stdout
.trim()
.split('\n')
.filter((f) => f);
} catch {
return [];
}
}
async function getMergeBase(base: string): Promise<string> {
try {
const result = await execa('git', ['merge-base', base, 'HEAD']);
return result.stdout.trim();
} catch {
return base;
}
}
export async function getChangedFiles(base: string): Promise<string[]> {
const files = new Set<string>();
// Find where we branched from (merge-base), not current base HEAD
const mergeBase = await getMergeBase(base);
// Committed changes since branching from base
for (const f of await getGitFiles(['diff', '--name-only', mergeBase])) {
files.add(f);
}
// Uncommitted changes (staged + unstaged)
for (const f of await getGitFiles(['diff', '--name-only', 'HEAD'])) {
files.add(f);
}
// Untracked files (new files not yet added to git)
for (const f of await getGitFiles([
'ls-files',
'--others',
'--exclude-standard',
])) {
files.add(f);
}
return Array.from(files);
}