Egonex-AI/Understand-Anything · error · Error

git ${args[0]} failed: ${result.stderr || result.error || re

Error message

git ${args[0]} failed: ${result.stderr || result.error || result.status}

What it means

The `git()` helper in validate-incremental-symbols.mjs runs a git command via spawnSync in the project root and throws whenever git exits with a non-zero status. The thrown message includes the failing subcommand and git's stderr (or the error object / exit status when stderr is empty). It exists because incremental symbol validation depends on git state (rev-parse HEAD, git diff --quiet) and cannot proceed safely if any git invocation fails.

Source

Thrown at understand-anything-plugin/skills/understand/validate-incremental-symbols.mjs:288

        }
      }
    }
    missing.push(entry);
  }
  return {
    filePath: previous.filePath,
    beforeCount: previous.nodes.length,
    afterCount: current.nodes.length,
    beforeSymbolCount: oldSymbols.length,
    afterSymbolCount: newSymbols.length,
    missing,
    replacements,
  };
}

export function git(root, args) {
  const result = spawnSync('git', args, { cwd: root, encoding: 'utf8', maxBuffer: 256 * 1024 * 1024 });
  if (result.status !== 0) throw new Error(`git ${args[0]} failed: ${result.stderr || result.error || result.status}`);
  return result.stdout;
}

export function loadSymbolContext(projectRoot, intermediateDir) {
  const plan = readJson(join(intermediateDir, 'incremental-plan.json'));
  const baseline = readJson(join(intermediateDir, 'incremental-symbol-baseline.json'));
  if (baseline.version !== 1 || baseline.baseCommit !== plan.baseCommit || baseline.headCommit !== plan.headCommit
    || !Array.isArray(baseline.files)) throw new Error('Symbol baseline does not match the incremental plan');
  const paths = baseline.files.map(file => file.filePath).sort();
  if (JSON.stringify(paths) !== JSON.stringify([...plan.filesToReanalyze].sort())
    || paths.some(path => !normalizePath(path) || (plan.deletedFiles ?? []).includes(path))
    || new Set(paths).size !== paths.length) {
    throw new Error('Symbol baseline file inventory does not match the incremental plan');
  }
  if (git(projectRoot, ['rev-parse', 'HEAD']).trim() !== plan.headCommit) {
    throw new Error('HEAD changed since prepare; baseline not advanced');
  }
  // Check every analyzer input, even if all IDs survive and parsing is skipped.

View on GitHub (pinned to 07edf82a04)

Solutions

  1. Read the stderr in the message and fix the underlying git failure (e.g. `git fetch` the missing commit, `git status` to repair the index).
  2. Verify you are running the script from inside a valid git worktree: `git -C <root> rev-parse --is-inside-work-tree`.
  3. Ensure git is installed and on PATH (`git --version`).
  4. For shallow clones, run `git fetch --unshallow` (or deepen) so the plan's base/head commits exist locally.
  5. If the repo is corrupt, re-clone or run `git fsck` to diagnose.

Example fix

// before: running validator in a non-repo directory
node validate-incremental-symbols.mjs /tmp/not-a-repo
// Error: git rev-parse failed: fatal: not a git repository...

// after: run inside the project git root
cd /path/to/project && node validate-incremental-symbols.mjs .
Defensive patterns

Strategy: try-catch

Validate before calling

import { execFileSync } from 'node:child_process';
function assertGitRepo(root) {
  execFileSync('git', ['-C', root, 'rev-parse', '--is-inside-work-tree'], { stdio: 'ignore' });
}

Try / catch

try {
  validateIncrementalSymbols({ projectRoot, intermediateDir });
} catch (err) {
  if (String(err.message).startsWith('git ')) {
    console.error('git operation failed; check repo state:', err.message);
  } else throw err;
}

Prevention

When it happens

Trigger: Any call to `git(root, args)` where the spawned `git <args[0]>` exits non-zero, e.g. `git(root, ['rev-parse','HEAD'])` when root is not inside a git worktree, or `git(root, ['diff','--quiet',headCommit,'--',...paths])` when headCommit does not exist locally.

Common situations: Running the validator outside a git repository or in a worktree with a broken .git; referencing a commit hash that was garbage-collected or never fetched; shallow clones lacking the base commit; git not installed or not on PATH (result.error set, status null); corrupt index requiring `git reset`.

Understand the failure class

Background: "git command failed": what it means when a tool shells out to git and git exits non-zero — this error's family across 21 libraries.

Related errors


AI-assisted analysis of Egonex-AI/Understand-Anything@07edf82a04 (2026-09-07). Data as JSON: /api/errors/e0978d2b3f06b2d2. Report an issue: GitHub.