From bafe7e9ede5a773187abd447ff194eb7b5ca385b Mon Sep 17 00:00:00 2001 From: di-sukharev Date: Wed, 29 Mar 2023 11:31:27 +0800 Subject: [PATCH] refactor(prepare-commit-msg-hook.ts): simplify conditional statements The conditional statements in the prepareCommitMessageHook function have been simplified to improve readability. The first conditional statement now checks if there are no staged files and no changed files, and if so, it will output a message and exit the process. The second conditional statement now checks if there are no staged files but there are changed files, and if so, it will add the changed files to the staging area. --- src/commands/prepare-commit-msg-hook.ts | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/commands/prepare-commit-msg-hook.ts b/src/commands/prepare-commit-msg-hook.ts index afde485..00aa835 100644 --- a/src/commands/prepare-commit-msg-hook.ts +++ b/src/commands/prepare-commit-msg-hook.ts @@ -20,12 +20,13 @@ export const prepareCommitMessageHook = async () => { const stagedFiles = await getStagedFiles(); const changedFiles = await getChangedFiles(); - if (!stagedFiles && changedFiles) await gitAdd({ files: changedFiles }); - else { + if (!stagedFiles && !changedFiles) { outro('No changes detected, write some code and run `oc` again'); process.exit(1); } + if (!stagedFiles && changedFiles) await gitAdd({ files: changedFiles }); + const staged = await getStagedFiles(); if (!staged) return;