From 3251879a534a16ea0cc65be660fbdab59e7d0ad6 Mon Sep 17 00:00:00 2001 From: Neema Boutorabi Date: Mon, 27 Oct 2025 12:54:54 -0700 Subject: [PATCH] Check for valid git repo earlier in commit workflow feat(commit.ts): add error handling for assertGitRepo when committing to improve user feedback. --- src/commands/commit.ts | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/src/commands/commit.ts b/src/commands/commit.ts index f86016e4..fb924183 100644 --- a/src/commands/commit.ts +++ b/src/commands/commit.ts @@ -52,11 +52,10 @@ const generateCommitMessageFromGitDiff = async ({ fullGitMojiSpec = false, skipCommitConfirmation = false }: GenerateCommitMessageFromGitDiffParams): Promise => { - await assertGitRepo(); const commitGenerationSpinner = spinner(); - commitGenerationSpinner.start('Generating the commit message'); - try { + await assertGitRepo(); + commitGenerationSpinner.start('Generating the commit message'); let commitMessage = await generateCommitMessageByDiff( diff, fullGitMojiSpec, @@ -226,6 +225,14 @@ export async function commit( fullGitMojiSpec: boolean = false, skipCommitConfirmation: boolean = false ) { + try { + await assertGitRepo(); + } catch (error) { + const err = error as Error; + outro(`${chalk.red('✖')} ${err?.message || err}`); + process.exit(1); + } + if (isStageAllFlag) { const changedFiles = await getChangedFiles();