diff --git a/src/commands/prepare-commit-msg-hook.ts b/src/commands/prepare-commit-msg-hook.ts index e1f7348b..561427d6 100644 --- a/src/commands/prepare-commit-msg-hook.ts +++ b/src/commands/prepare-commit-msg-hook.ts @@ -77,7 +77,7 @@ export const prepareCommitMessageHook = async ( const fileContent = await fs.readFile(messageFilePath); const commentedError = String(error).replace(new RegExp('^', 'gm'), '# '); - const message = `\n\n# ---------- [OpenCommit] ---------- #\n# Failed to generate the commit message.\n# To cancel the commit, just close this window without making any changes.\n\n${commentedError}\n\n${fileContent.toString()}` + const message = `\n\n# ---------- [OpenCommit] ---------- #\n# Failed to generate the commit message.\n# To cancel the commit, just close this window without making any changes.\n\n${commentedError}\n\n${fileContent.toString()}`; await fs.writeFile(messageFilePath, message); } catch (error) { diff --git a/src/generateCommitMessageFromGitDiff.ts b/src/generateCommitMessageFromGitDiff.ts index 01f04a67..f46d6e53 100644 --- a/src/generateCommitMessageFromGitDiff.ts +++ b/src/generateCommitMessageFromGitDiff.ts @@ -168,6 +168,15 @@ export const generateCommitMessageByDiff = async ( const commitMessages = await Promise.all(commitMessagePromises); + // When OCO_ONE_LINE_COMMIT is enabled, combine the first line of each + // split-diff message into a single line instead of joining with '\n\n'. + if (config.OCO_ONE_LINE_COMMIT) { + return commitMessages + .filter(Boolean) + .map((msg) => msg!.split('\n')[0].trim()) + .join('; '); + } + return commitMessages.join('\n\n'); } diff --git a/src/prompts.ts b/src/prompts.ts index 0f2f7281..d860a151 100644 --- a/src/prompts.ts +++ b/src/prompts.ts @@ -240,7 +240,15 @@ export const getMainCommitPrompt = async ( } // Replace example prompt with a prompt that's generated by OpenAI for the commitlint config. - const commitLintConfig = await utils.getCommitlintLLMConfig(); + let commitLintConfig = await utils.getCommitlintLLMConfig(); + + // Guard against outdated or corrupted config files that are missing the + // prompts field (e.g. generated by an older version of opencommit). + if (!Array.isArray(commitLintConfig.prompts)) { + note('Commitlint LLM config is missing prompts, regenerating...'); + await configureCommitlintIntegration(true); + commitLintConfig = await utils.getCommitlintLLMConfig(); + } return [ commitlintPrompts.INIT_MAIN_PROMPT(