fix: handle missing prompts in commitlint config and OCO_ONE_LINE_COMMIT for split diffs
Problem
This PR fixes two bugs:
Bug 1 — Fixes #482: TypeError: Cannot read properties of undefined (reading 'join') with @commitlint
When the .opencommit-commitlint cache file exists but is missing the prompts field (e.g. generated by an older version of opencommit or manually edited), INIT_MAIN_PROMPT in src/modules/commitlint/prompts.ts crashes trying to call .join() on undefined.
Steps to reproduce:
oco config set OCO_PROMPT_MODULE=@commitlint
git add .
oco
Bug 2 — Fixes #474: OCO_ONE_LINE_COMMIT=true has no effect on large diffs
When a staged diff exceeds the context window it gets split into chunks, each generating its own commit message. These messages were then joined with \n\n, producing a multi-line result regardless of OCO_ONE_LINE_COMMIT=true.
Solution
Fix 1: After reading the cached commitlint config, check whether prompts is a valid array. If not (outdated/corrupted file), force a regeneration of the config before proceeding. This recovers gracefully instead of crashing.
Fix 2: When OCO_ONE_LINE_COMMIT is enabled and the diff was split into multiple chunks, extract the first line from each chunk's commit message and join them with '; ' to produce a single-line result.
Testing
- TypeScript typecheck passes (
tsc --noEmit) - Fix 1 is guarded by
Array.isArray()so valid configs are not affected - Fix 2 only activates when
OCO_ONE_LINE_COMMIT=trueand the diff was large enough to be split
@octo-patch please fix the tests
@di-sukharev pushed c10f12b. The CI failure was actually npm run format:check (prettier), not the test runner — lint and typecheck already pass. Ran npx prettier --write on the two touched files (src/commands/prepare-commit-msg-hook.ts, src/prompts.ts) and re-verified npm run format:check and npm run lint are clean locally.