INNER CODE UNIT · JavaScript
stageFile
karanb192/claude-code-hooks · plugins/auto-stage/auto-stage.js:55
function stageFile(filePath) {
try {
const dir = path.dirname(filePath);
// No shell: the path is passed as an argv element, so quotes, $(), and
// backticks in a filename cannot break out. `--` stops a leading dash
// from being read as a git option.
execFileSync('git', ['add', '--', filePath], { cwd: dir, stdio: 'pipe' });
return { success: true };
} catch (e) {
return { success: false, error: e.message };
}
}
async function main() {
let input = '';
for await (const chunk of process.stdin) input += chunk;
try {