can1357/oh-my-pi · error · Error

No staged changes to analyze

Error message

No staged changes to analyze

What it means

generateGitCommit requires staged changes to analyze. If nothing is staged it first attempts to stage all changes (when options.stageIfEmpty !== false); if the index is still empty after that, it throws because there is no diff to base a commit message on. This is the first of two staged-content checks (this one checks the file list).

Source

Thrown at packages/coding-agent/src/commit/conventional/service.ts:75

		` ${entries.length} file${entries.length === 1 ? "" : "s"} changed, ${insertions} insertion${insertions === 1 ? "" : "s"}(+), ${deletions} deletion${deletions === 1 ? "" : "s"}(-)`,
	);
	return `${lines.join("\n")}\n`;
}

/** Generate a commit message from the staged tree, staging all only when the index is empty. */
export async function generateGitCommit(options: GenerateGitCommitOptions): Promise<GeneratedGitCommit> {
	const repo = vcs.requireGit(options.cwd);
	const settings = await Settings.init({ cwd: options.cwd });
	const config = conventionalGenerationConfig(settings.getGroup("commit"));
	let stagedFiles = await repo.changedFiles({ cached: true }, options.signal);
	let stagedAll = false;
	if (stagedFiles.length === 0 && options.stageIfEmpty !== false) {
		options.onProgress?.("Staging all changes…");
		await repo.stageFiles([], options.signal);
		stagedAll = true;
		stagedFiles = await repo.changedFiles({ cached: true }, options.signal);
	}
	if (stagedFiles.length === 0) throw new Error("No staged changes to analyze");

	options.onProgress?.("Reading staged changes…");
	const initialDiff = await repo.diffText({ cached: true }, options.signal);
	const diff =
		Buffer.byteLength(initialDiff) <= config.maxDiffLength
			? initialDiff
			: await repo.diffText({ cached: true, context: 1 }, options.signal);
	if (!diff.trim()) throw new Error("No staged changes to analyze");

	const numstatEntries = await repo.numstat({ cached: true }, options.signal);
	const stat = renderStat(numstatEntries);
	const numstat = renderNumstat(numstatEntries);
	const context = await collectGenerationContext(options.cwd, options.signal);

	const inference = new LazyCommitInference(() => createOmpInference(options, settings, config));
	try {
		const result = await generateConventionalCommit({ diff, stat, numstat, config, inference, context });
		return { ...result, stagedAll };

View on GitHub (pinned to 9690622007)

Solutions

  1. Stage changes first: git add <files> (or run the generator before committing everything)
  2. Check git status — if the tree is clean there is nothing to commit
  3. Verify ignore rules aren't hiding your changes (.gitignore matching new files)
  4. Don't pass stageIfEmpty:false unless you guarantee a pre-populated index

Example fix

// before: throws when nothing staged
const msg = await generateGitCommit({ cwd, repo });
// after: pre-check
diff --no-index /dev/null /dev/null; git status --porcelain
git add -A
const msg = await generateGitCommit({ cwd, repo });
Defensive patterns

Strategy: validation

Validate before calling

const staged = await repo.changedFiles({ cached: true });
if (staged.length === 0) {
  await repo.stageFiles([]); // stage all, then re-check
}

Try / catch

try {
  const msg = await generateGitCommit(options);
} catch (err) {
  if (err instanceof Error && err.message === "No staged changes to analyze") {
    // inform user: nothing to commit
  }
  throw err;
}

Prevention

When it happens

Trigger: Calling generateGitCommit (via generated or runLegacyCommitCommand) in a repo where the index is empty AND staging-all yields nothing — i.e. a clean working tree, or all changes are untracked-but-ignored/unchanged, or stageIfEmpty is disabled with nothing pre-staged.

Common situations: Running the commit generator twice (second run: everything already committed), committing in a repo with only untracked files when stageFiles doesn't include untracked paths, or stageIfEmpty:false with a forgotten 'git add'.

Related errors


AI-assisted analysis of can1357/oh-my-pi@9690622007 (2026-08-31). Data as JSON: /api/errors/92a5cf3d7b650011. Report an issue: GitHub.