diff --git a/src/commands.ts b/src/commands.ts index 122a3ef..140fa4b 100644 --- a/src/commands.ts +++ b/src/commands.ts @@ -444,29 +444,41 @@ async function setupGitHooks({ selection, commitHookStatusBar, }: CommandDeps): Promise { - await setupGitCommitHooks(selection); - if ((await preCommitHooksExists()) /* && (await postCommitHooksExists()) */) { - commitHookStatusBar.setActive(true); - } else { - commitHookStatusBar.setActive(false); + try { + await removeExistingGitHooks(); + if ( + await preCommitHooksExists() /* && (await postCommitHooksExists()) */ + ) { + commitHookStatusBar.setActive(true); + } else { + commitHookStatusBar.setActive(false); + } + vscode.window.showInformationMessage( + `Git Hooks have been removed successfully from ${gitPreCommitHookFilePath} and ${gitPostCommitHookFilePath}.`, + ); + } catch { + return; } - vscode.window.showInformationMessage( - `Git Hooks have been added successfully under ${gitPreCommitHookFilePath} and ${gitPostCommitHookFilePath}`, - ); } async function removeGitHooks({ commitHookStatusBar, }: CommandDeps): Promise { - await removeExistingGitHooks(); - if ((await preCommitHooksExists())/* && (await postCommitHooksExists()) */) { - commitHookStatusBar.setActive(true); - } else { - commitHookStatusBar.setActive(false); + try { + await removeExistingGitHooks(); + if ( + await preCommitHooksExists() /* && (await postCommitHooksExists()) */ + ) { + commitHookStatusBar.setActive(true); + } else { + commitHookStatusBar.setActive(false); + } + vscode.window.showInformationMessage( + `Git Hooks have been removed successfully from ${gitPreCommitHookFilePath} and ${gitPostCommitHookFilePath}.`, + ); + } catch { + return; } - vscode.window.showInformationMessage( - `Git Hooks have been removed successfully from ${gitPreCommitHookFilePath} and ${gitPostCommitHookFilePath}.`, - ); } /** Replaces an existing `registry=` line or appends one, preserving other lines. */ diff --git a/src/commitHooks.ts b/src/commitHooks.ts index 9059351..4889378 100644 --- a/src/commitHooks.ts +++ b/src/commitHooks.ts @@ -36,7 +36,7 @@ export async function removeExistingGitHooks(): Promise { `An error occured during git check. Could not check if git repository is present in workspace.`, ); } - return; + throw err; } try { @@ -69,8 +69,8 @@ export async function removeExistingGitHooks(): Promise { vscode.window.showErrorMessage( `An error occured during git check. Could not check if git hook is present in workspace.`, ); - return; } + throw err; } } @@ -99,7 +99,7 @@ export async function setupGitCommitHooks( `An error occured during git check. Could not check if git repository is present in workspace.`, ); } - return; + throw err; } await removeExistingGitHooks();