Skip to content

Commit abd88c8

Browse files
vinistockgraphite-app[bot]
authored andcommitted
Avoid failing if the git extension is disabled (#3822)
### Motivation Closes #3685 If the git extension is disabled, trying to invoke `getAPI` may throw an error like the one reported in the issue. ### Implementation We can just wrap that call in a try/catch block since we fall back to the default, which is to consider the git root to be in the same place as the workspace path.
1 parent 975619f commit abd88c8

File tree

1 file changed

+8
-4
lines changed

1 file changed

+8
-4
lines changed

vscode/src/workspace.ts

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -69,11 +69,15 @@ export class Workspace implements WorkspaceInterface {
6969

7070
// If the git extension is available, use that to find the root of the git repository
7171
if (gitExtension) {
72-
const api = gitExtension.exports.getAPI(1);
73-
const repository = await api.openRepository(this.workspaceFolder.uri);
72+
try {
73+
const api = gitExtension.exports.getAPI(1);
74+
const repository = await api.openRepository(this.workspaceFolder.uri);
7475

75-
if (repository) {
76-
rootGitUri = repository.rootUri;
76+
if (repository) {
77+
rootGitUri = repository.rootUri;
78+
}
79+
} catch (_error: any) {
80+
// Git extension might be disabled
7781
}
7882
}
7983

0 commit comments

Comments
 (0)