From 43dc5e6c2b988a992ee7a25b385ec30ca5d94519 Mon Sep 17 00:00:00 2001 From: leoliu Date: Thu, 26 Jun 2025 23:41:58 +0800 Subject: [PATCH] feat(commit.ts): enable users to edit commit message before committing --- src/commands/commit.ts | 28 ++++++++++++++++++++-------- 1 file changed, 20 insertions(+), 8 deletions(-) diff --git a/src/commands/commit.ts b/src/commands/commit.ts index 1e7f2af..837c929 100644 --- a/src/commands/commit.ts +++ b/src/commands/commit.ts @@ -1,5 +1,5 @@ import { - confirm, + text, intro, isCancel, multiselect, @@ -85,15 +85,27 @@ ${commitMessage} ${chalk.grey('——————————————————')}` ); - const isCommitConfirmedByUser = - skipCommitConfirmation || - (await confirm({ - message: 'Confirm the commit message?' - })); + const userAction = skipCommitConfirmation + ? 'Yes' + : await select({ + message: 'Confirm the commit message?', + options: [ + { value: 'Yes', label: 'Yes' }, + { value: 'No', label: 'No' }, + { value: 'Edit', label: 'Edit' } + ] + }); - if (isCancel(isCommitConfirmedByUser)) process.exit(1); + if (isCancel(userAction)) process.exit(1); - if (isCommitConfirmedByUser) { + if (userAction === 'Edit') { + commitMessage = await text({ + message: 'Please edit the commit message: (press Enter to continue)', + initialValue: commitMessage + }); + } + + if (userAction === 'Yes' || userAction === 'Edit') { const committingChangesSpinner = spinner(); committingChangesSpinner.start('Committing the changes'); const { stdout } = await execa('git', [