From ec2e4c628c76f365a89a61946bb7c6ccf0bd8f18 Mon Sep 17 00:00:00 2001 From: di-sukharev Date: Thu, 16 Mar 2023 23:15:56 +0800 Subject: [PATCH] fix(commit.ts): fix typo in outro message feat(commit.ts): add support for staging all files and generating commit message when no files are staged feat(commit.ts): add support for committing changes when no files are staged and some files are changed but not staged --- src/commands/commit.ts | 35 +++++++++-------------------------- 1 file changed, 9 insertions(+), 26 deletions(-) diff --git a/src/commands/commit.ts b/src/commands/commit.ts index a48ff6e..381b959 100644 --- a/src/commands/commit.ts +++ b/src/commands/commit.ts @@ -60,8 +60,11 @@ ${chalk.grey('——————————————————')}` if (isCommitConfirmedByUser && !isCancel(isCommitConfirmedByUser)) { const { stdout } = await execa('git', ['commit', '-m', commitMessage]); + outro(`${chalk.green('✔')} successfully committed`); + outro(stdout); + const isPushConfirmedByUser = await confirm({ message: 'Do you want to run `git push`?' }); @@ -83,8 +86,8 @@ export async function commit(isStageAllFlag = false) { const changedFiles = await getChangedFiles(); if (changedFiles) await gitAdd({ files: changedFiles }); else { - outro("No changes detected, write some code and run `oc` again"); - process.exit(1); + outro('No changes detected, write some code and run `oc` again'); + process.exit(1); } } @@ -105,29 +108,7 @@ export async function commit(isStageAllFlag = false) { const stagedFilesSpinner = spinner(); stagedFilesSpinner.start('Counting staged files'); - if (!stagedFiles.length && isStageAllFlag) { - outro( - `${chalk.red( - 'No changes detected' - )} — write some code, stage the files ${chalk - .hex('0000FF') - .bold('`git add .`')} and rerun ${chalk - .hex('0000FF') - .bold('`oc`')} command.` - ); - - process.exit(1); - } - if (!stagedFiles.length) { - outro( - `${chalk.red('Nothing to commit')} — stage the files ${chalk - .hex('0000FF') - .bold('`git add .`')} and rerun ${chalk - .hex('0000FF') - .bold('`oc`')} command.` - ); - stagedFilesSpinner.stop('No files are staged'); const isStageAllAndCommitConfirmedByUser = await confirm({ message: 'Do you want to stage all files and generate commit message?' @@ -137,7 +118,8 @@ export async function commit(isStageAllFlag = false) { isStageAllAndCommitConfirmedByUser && !isCancel(isStageAllAndCommitConfirmedByUser) ) { - return await commit(true); + await commit(true); + process.exit(1); } if (stagedFiles.length === 0 && changedFiles.length > 0) { @@ -154,7 +136,8 @@ export async function commit(isStageAllFlag = false) { await gitAdd({ files }); } - commit(false); + await commit(false); + process.exit(1); } stagedFilesSpinner.stop(