Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
44 changes: 28 additions & 16 deletions src/commands.ts
Original file line number Diff line number Diff line change
Expand Up @@ -444,29 +444,41 @@ async function setupGitHooks({
selection,
commitHookStatusBar,
}: CommandDeps): Promise<void> {
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<void> {
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. */
Expand Down
6 changes: 3 additions & 3 deletions src/commitHooks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ export async function removeExistingGitHooks(): Promise<void> {
`An error occured during git check. Could not check if git repository is present in workspace.`,
);
}
return;
throw err;
}

try {
Expand Down Expand Up @@ -69,8 +69,8 @@ export async function removeExistingGitHooks(): Promise<void> {
vscode.window.showErrorMessage(
`An error occured during git check. Could not check if git hook is present in workspace.`,
);
return;
}
throw err;
}
}

Expand Down Expand Up @@ -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();
Expand Down