Skip to content

Commit 881f07e

Browse files
committed
fix(prepare-commit-msg-hook): simplify commit message generation logic for clarity and maintainability
1 parent 3a255a3 commit 881f07e

File tree

1 file changed

+7
-5
lines changed

1 file changed

+7
-5
lines changed

src/commands/prepare-commit-msg-hook.ts

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -56,12 +56,14 @@ export const prepareCommitMessageHook = async (
5656

5757
const fileContent = await fs.readFile(messageFilePath);
5858

59-
const divider = '# ---------- [OpenCommit] ---------- #';
59+
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()}`;
60+
const messageWithoutComment = `${commitMessage}\n\n${fileContent.toString()}`;
6061

61-
await fs.writeFile(
62-
messageFilePath,
63-
`${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()}`
64-
);
62+
const message = config.OCO_HOOK_AUTO_UNCOMMENT
63+
? messageWithoutComment
64+
: messageWithComment;
65+
66+
await fs.writeFile(messageFilePath, message);
6567
} catch (error) {
6668
outro(`${chalk.red('✖')} ${error}`);
6769
process.exit(1);

0 commit comments

Comments
 (0)