From 881f07eebee99073d6bd3e6226213954141c3458 Mon Sep 17 00:00:00 2001 From: Phantas Weng Date: Tue, 8 Jul 2025 05:31:44 +0000 Subject: [PATCH] fix(prepare-commit-msg-hook): simplify commit message generation logic for clarity and maintainability --- src/commands/prepare-commit-msg-hook.ts | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/src/commands/prepare-commit-msg-hook.ts b/src/commands/prepare-commit-msg-hook.ts index 0174ea5..776bf90 100644 --- a/src/commands/prepare-commit-msg-hook.ts +++ b/src/commands/prepare-commit-msg-hook.ts @@ -56,12 +56,14 @@ export const prepareCommitMessageHook = async ( const fileContent = await fs.readFile(messageFilePath); - const divider = '# ---------- [OpenCommit] ---------- #'; + const messageWithComment = `# ${commitMessage}\n\n# ---------- [OpenCommit] ---------- #\n# Remove the # above to use this generated commit message.\n# To cancel the commit, just close this window without making any changes.\n\n${fileContent.toString()}`; + const messageWithoutComment = `${commitMessage}\n\n${fileContent.toString()}`; - await fs.writeFile( - messageFilePath, - `${config.OCO_HOOK_AUTO_UNCOMMENT ? '' : '# '}${commitMessage}\n\n${divider}\n# Remove the # above to use this generated commit message.\n# To cancel the commit, just close this window without making any changes.\n\n${fileContent.toString()}` - ); + const message = config.OCO_HOOK_AUTO_UNCOMMENT + ? messageWithoutComment + : messageWithComment; + + await fs.writeFile(messageFilePath, message); } catch (error) { outro(`${chalk.red('✖')} ${error}`); process.exit(1);