Description
hasCommits() catches every error from git rev-list --count HEAD and returns false. The caller in suggestCommand() interprets false specifically as “this repository has no commits yet.”
That means an actual Git failure — for example an unreadable/corrupt object database or an invalid HEAD — is reported to the user as an empty repository instead of surfacing the Git error.
Location
src/git/diff.ts:96-108
export function hasCommits(): boolean {
try {
const count = execFileSync(getGitExecutable(), ['rev-list', '--count', 'HEAD'], {
encoding: 'utf-8',
stdio: 'pipe',
}).trim();
return Number.parseInt(count, 10) > 0;
} catch {
return false;
}
}
The result is consumed by src/commands/suggest.ts as the explicit “no commits” precondition.
Steps to reproduce
- Use a Git repository with a valid working tree but a broken
HEAD/object database, or inject a non-zero Git error from the hasCommits() dependency in a unit test.
- Run
commit-echo suggest.
- Observe the “This repository has no commits yet” message.
Expected behavior
An actually empty repository should return false, but unrelated Git failures should propagate as Git errors so the user can repair the repository.
Actual behavior
All rev-list failures collapse to the same boolean value, making empty repositories indistinguishable from broken repositories.
Suggested fix
Distinguish the legitimate empty-history case from command failure — for example by checking/verifying HEAD separately and only returning false when Git confirms that no commit exists. Preserve and surface stderr for other failures.
Impact
Users can be sent down the wrong recovery path, and genuine repository corruption or access failures are masked. This is especially confusing because the current code already has explicit handling for the normal zero-commit repository case.
Reviewed against current main at c67ff967a018d5fd4b032f6ef6a4981ac9d76a12.
Description
hasCommits()catches every error fromgit rev-list --count HEADand returnsfalse. The caller insuggestCommand()interpretsfalsespecifically as “this repository has no commits yet.”That means an actual Git failure — for example an unreadable/corrupt object database or an invalid
HEAD— is reported to the user as an empty repository instead of surfacing the Git error.Location
src/git/diff.ts:96-108The result is consumed by
src/commands/suggest.tsas the explicit “no commits” precondition.Steps to reproduce
HEAD/object database, or inject a non-zero Git error from thehasCommits()dependency in a unit test.commit-echo suggest.Expected behavior
An actually empty repository should return false, but unrelated Git failures should propagate as Git errors so the user can repair the repository.
Actual behavior
All
rev-listfailures collapse to the same boolean value, making empty repositories indistinguishable from broken repositories.Suggested fix
Distinguish the legitimate empty-history case from command failure — for example by checking/verifying
HEADseparately and only returning false when Git confirms that no commit exists. Preserve and surface stderr for other failures.Impact
Users can be sent down the wrong recovery path, and genuine repository corruption or access failures are masked. This is especially confusing because the current code already has explicit handling for the normal zero-commit repository case.
Reviewed against current
mainatc67ff967a018d5fd4b032f6ef6a4981ac9d76a12.