Skip to content

fix(commit): tolerate initial-commit repos in branch-name lookup (#844)#846

Merged
gfargo merged 1 commit intomainfrom
fix/initial-commit-head-crash-844
May 5, 2026
Merged

fix(commit): tolerate initial-commit repos in branch-name lookup (#844)#846
gfargo merged 1 commit intomainfrom
fix/initial-commit-head-crash-844

Conversation

@gfargo
Copy link
Copy Markdown
Owner

@gfargo gfargo commented May 5, 2026

Closes #844.

Summary

coco commit ran the full diff pipeline (collect → pre-process → consolidate → generate) and then crashed with fatal: ambiguous argument 'HEAD' when the post-summary step asked for the current branch via git rev-parse --abbrev-ref HEAD. On an initial-commit repo (fresh git init, no commits yet), HEAD doesn't resolve via rev-parse and the call fails fatally — but by that point the pipeline has already burned several minutes of LLM calls summarizing the staged changes, so the user pays the full cost and gets nothing back.

Fix

git symbolic-ref --short HEAD still reports the configured initial branch name even with no commits, so getCurrentBranchName now falls through to it on rev-parse failure and to an empty string only if both calls fail. Every caller already handles an empty branch context as "no branch info", so the no-HEAD case now runs the commit message generation to completion instead of aborting after the heavy lifting is done.

Test plan

  • npm run lint
  • npm run test:jest (1199 tests pass — the previous test that asserted the helper throws was replaced with five new tests covering the rev-parse path, the symbolic-ref fallback, output trimming, the both-fail empty-string path, and confirmation that symbolic-ref isn't called when rev-parse succeeds)
  • npm run build
  • npm run test:cli
  • Manual: mkdir foo && cd foo && git init && touch a.txt && git add . && coco commit -a 'initial commit' --verbose — pipeline should complete and present a draft instead of crashing at the end

Follow-up

Performance work (4-minute pipeline on a 43-file initial commit) is tracked separately as #845. The crash fix here makes that performance cost no longer wasted, but the pipeline still needs the optimization pass.

`coco commit` ran the full diff pipeline (collect → pre-process →
consolidate → generate) and then crashed with "fatal: ambiguous
argument 'HEAD'" when the post-summary step asked for the current
branch via `git rev-parse --abbrev-ref HEAD`. On an initial-commit
repo (fresh `git init`, no commits yet), HEAD doesn't resolve via
rev-parse and the call fails fatally — but by that point the
pipeline has already burned several minutes of LLM calls
summarizing the staged changes, so the user pays the full cost
and gets nothing back.

`git symbolic-ref --short HEAD` still reports the configured
initial branch name even with no commits, so getCurrentBranchName
now falls through to it on rev-parse failure and to an empty
string only if both calls fail. Every caller already handles an
empty branch context as "no branch info", so the no-HEAD case now
runs the commit message generation to completion instead of
aborting after the heavy lifting is done.

Closes #844.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
@gfargo gfargo merged commit 11cc51a into main May 5, 2026
7 of 8 checks passed
@gfargo gfargo deleted the fix/initial-commit-head-crash-844 branch May 5, 2026 14:27
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

coco commit crashes on initial-commit repo (no HEAD) after the entire summary pipeline ran

1 participant