INNER CODE UNIT · JavaScript

isInGitRepo

karanb192/claude-code-hooks · plugins/auto-stage/auto-stage.js:45

function isInGitRepo(filePath) {
  try {
    const dir = path.dirname(filePath);
    execSync('git rev-parse --git-dir', { cwd: dir, stdio: 'pipe' });
    return true;
  } catch {
    return false;
  }
}

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 };

View source record →

📰 Research Paper
Loading…
⏳ Fetching content…