Files
renovate/tools/agents/hooks/utils/git.ts
Michael Kriese 7c0592b540 chore(tools): allow unsafe askpass in agent hooks git config (#45245)
VS Code sets `GIT_ASKPASS`, which simple-git rejects as unsafe unless
`allowUnsafeAskPass` is enabled, breaking the agent hooks when run from
a VS Code terminal.

Co-authored-by: Claude Opus 5 (1M context) <noreply@anthropic.com>
2026-08-12 13:00:59 +00:00

63 lines
1.4 KiB
TypeScript

import { type SimpleGit, type SimpleGitOptions, simpleGit } from 'simple-git';
const config: Partial<SimpleGitOptions> = {
completion: { onClose: true, onExit: false },
config: ['core.quotePath=false'],
unsafe: {
allowUnsafePager: true,
allowUnsafeEditor: true,
allowUnsafeAskPass: true, // set by vscode
},
};
const git: SimpleGit = simpleGit(config).env({
...process.env,
LANG: 'C.UTF-8',
LC_ALL: 'C.UTF-8',
});
export async function getRepoRoot(dir?: string): Promise<string | null> {
const instance = dir ? simpleGit({ ...config, baseDir: dir }) : git;
try {
const out = await instance.revparse(['--show-toplevel']);
return out.trim() || null;
} catch {
return null;
}
}
async function getBaseRef(): Promise<string> {
try {
const out = await git.raw(['merge-base', 'origin/main', 'HEAD']);
if (out.trim()) {
return out.trim();
}
} catch {
// origin/main not available
}
try {
const out = await git.revparse([
'--abbrev-ref',
'--symbolic-full-name',
'@{u}',
]);
if (out.trim()) {
return out.trim();
}
} catch {
// No upstream configured
}
return 'HEAD';
}
export async function getChangedFiles(): Promise<string[]> {
const baseRef = await getBaseRef();
const out = await git.diff(['--name-only', '--diff-filter=ACMR', baseRef]);
return out
.trim()
.split('\n')
.filter((f) => f.length > 0);
}