@@ -10,6 +10,24 @@ import { API } from "./api/git";
1010import { makeAndFillCommitMsg } from "./autofill" ;
1111import { getGitExtension } from "./gitExtension" ;
1212
13+ function _validateFoundRepos ( git : API ) {
14+ let msg = "" ;
15+
16+ if ( ! git ) {
17+ msg = "Unable to load Git Extension" ;
18+ }
19+ if ( git . repositories . length === 0 ) {
20+ msg =
21+ "No repos found. Please open a repo or run `git init` then try this extension again." ;
22+ }
23+
24+ if ( msg ) {
25+ vscode . window . showErrorMessage ( msg ) ;
26+
27+ throw new Error ( msg ) ;
28+ }
29+ }
30+
1331/**
1432 * Run autofill against one of multiples in the workspace.
1533 *
@@ -38,19 +56,8 @@ async function _handleRepo(git: API) {
3856}
3957
4058async function _chooseRepoForAutofill ( uri ?: vscode . Uri ) : Promise < void > {
41- const git = getGitExtension ( ) ;
42-
43- if ( ! git ) {
44- vscode . window . showErrorMessage ( "Unable to load Git Extension" ) ;
45- return ;
46- }
47-
48- if ( git . repositories . length === 0 ) {
49- vscode . window . showErrorMessage (
50- "No repos found. Please open a repo or run `git init` then try this extension again."
51- ) ;
52- return ;
53- }
59+ const git = getGitExtension ( ) ! ;
60+ _validateFoundRepos ( git ) ;
5461
5562 vscode . commands . executeCommand ( "workbench.view.scm" ) ;
5663
@@ -85,4 +92,4 @@ export function activate(context: vscode.ExtensionContext) {
8592}
8693
8794// eslint-disable-next-line @typescript-eslint/no-empty-function
88- export function deactivate ( ) { }
95+ export function deactivate ( ) { }
0 commit comments