fix(commit): tolerate initial-commit repos in branch-name lookup (#844)#846
Merged
fix(commit): tolerate initial-commit repos in branch-name lookup (#844)#846
Conversation
`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>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Closes #844.
Summary
coco commitran the full diff pipeline (collect → pre-process → consolidate → generate) and then crashed withfatal: ambiguous argument 'HEAD'when the post-summary step asked for the current branch viagit rev-parse --abbrev-ref HEAD. On an initial-commit repo (freshgit 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 HEADstill reports the configured initial branch name even with no commits, sogetCurrentBranchNamenow 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 lintnpm 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 buildnpm run test:climkdir 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 endFollow-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.