55 * the prepareCommitMsg module to a target branch.
66 */
77import * as vscode from "vscode" ;
8- import { API } from "./api/git" ;
8+ import { API , Repository } from "./api/git" ;
99import { makeAndFillCommitMsg } from "./autofill" ;
1010import { getGitExtension } from "./gitExtension" ;
1111
@@ -27,9 +27,12 @@ function _validateFoundRepos(git: API) {
2727}
2828
2929/**
30- * Run autofill against one of multiples in the workspace or when using GitLens on a single repo.
30+ * Get current repo when using multiples in the workspace ( or when using GitLens on a single repo) .
3131 */
32- async function _handleRepos ( git : API , sourceControl : vscode . SourceControl ) {
32+ async function _handleRepos (
33+ git : API ,
34+ sourceControl : vscode . SourceControl
35+ ) : Promise < Repository | undefined > {
3336 const selectedRepo = git . repositories . find ( repository => {
3437 const uri = sourceControl . rootUri ;
3538 if ( ! uri ) {
@@ -41,19 +44,14 @@ async function _handleRepos(git: API, sourceControl: vscode.SourceControl) {
4144 return repoPath === uri . path ;
4245 } ) ;
4346
44- if ( selectedRepo ) {
45- await makeAndFillCommitMsg ( selectedRepo ) ;
46- } else {
47- vscode . window . showErrorMessage ( "No repos found" ) ;
48- }
47+ return selectedRepo ;
4948}
5049
5150/**
52- * Run autofill flow for a single repo in the workspace.
51+ * Return a repo for single repo in the workspace.
5352 */
54- async function _handleRepo ( git : API ) {
55- const targetRepo = git . repositories [ 0 ] ;
56- await makeAndFillCommitMsg ( targetRepo ) ;
53+ async function _handleRepo ( git : API ) : Promise < Repository > {
54+ return git . repositories [ 0 ] ;
5755}
5856
5957/**
@@ -65,11 +63,17 @@ async function _chooseRepoForAutofill(sourceControl?: vscode.SourceControl) {
6563
6664 vscode . commands . executeCommand ( "workbench.view.scm" ) ;
6765
68- if ( sourceControl ) {
69- _handleRepos ( git , sourceControl ) ;
70- } else {
71- _handleRepo ( git ) ;
66+ const selectedRepo = sourceControl
67+ ? await _handleRepos ( git , sourceControl )
68+ : await _handleRepo ( git ) ;
69+
70+ if ( ! selectedRepo ) {
71+ const msg = "No repos found" ;
72+ vscode . window . showErrorMessage ( msg ) ;
73+ throw new Error ( msg ) ;
7274 }
75+
76+ await makeAndFillCommitMsg ( selectedRepo ) ;
7377}
7478
7579/**
0 commit comments