Skip to content

Commit 43dc5e6

Browse files
committed
feat(commit.ts): enable users to edit commit message before committing
1 parent 7945f44 commit 43dc5e6

File tree

1 file changed

+20
-8
lines changed

1 file changed

+20
-8
lines changed

src/commands/commit.ts

Lines changed: 20 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import {
2-
confirm,
2+
text,
33
intro,
44
isCancel,
55
multiselect,
@@ -85,15 +85,27 @@ ${commitMessage}
8585
${chalk.grey('——————————————————')}`
8686
);
8787

88-
const isCommitConfirmedByUser =
89-
skipCommitConfirmation ||
90-
(await confirm({
91-
message: 'Confirm the commit message?'
92-
}));
88+
const userAction = skipCommitConfirmation
89+
? 'Yes'
90+
: await select({
91+
message: 'Confirm the commit message?',
92+
options: [
93+
{ value: 'Yes', label: 'Yes' },
94+
{ value: 'No', label: 'No' },
95+
{ value: 'Edit', label: 'Edit' }
96+
]
97+
});
98+
99+
if (isCancel(userAction)) process.exit(1);
93100

94-
if (isCancel(isCommitConfirmedByUser)) process.exit(1);
101+
if (userAction === 'Edit') {
102+
commitMessage = await text({
103+
message: 'Please edit the commit message: (press Enter to continue)',
104+
initialValue: commitMessage
105+
});
106+
}
95107

96-
if (isCommitConfirmedByUser) {
108+
if (userAction === 'Yes' || userAction === 'Edit') {
97109
const committingChangesSpinner = spinner();
98110
committingChangesSpinner.start('Committing the changes');
99111
const { stdout } = await execa('git', [

0 commit comments

Comments
 (0)