Skip to content

fix: handle missing prompts in commitlint config and OCO_ONE_LINE_COMMIT for split diffs#554

Open
octo-patch wants to merge 1 commit intodi-sukharev:masterfrom
octo-patch:fix/issue-482-474-commitlint-one-line-commit
Open

fix: handle missing prompts in commitlint config and OCO_ONE_LINE_COMMIT for split diffs#554
octo-patch wants to merge 1 commit intodi-sukharev:masterfrom
octo-patch:fix/issue-482-474-commitlint-one-line-commit

Conversation

@octo-patch
Copy link
Copy Markdown

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=true and the diff was large enough to be split

@di-sukharev
Copy link
Copy Markdown
Owner

@octo-patch please fix the tests

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.

[Bug]: Cannot read properties of undefined (@commitlint) [Bug]: OCO_ONE_LINE_COMMIT=true has no effect

2 participants