diff --git a/vscode/src/repository/repositoryHelpers.ts b/vscode/src/repository/repositoryHelpers.ts index 01df55104b18..2cbbf3524b8b 100644 --- a/vscode/src/repository/repositoryHelpers.ts +++ b/vscode/src/repository/repositoryHelpers.ts @@ -7,22 +7,27 @@ export function repositoryRemoteUrl(uri: vscode.Uri): string | undefined { } function gitRepositoryRemoteUrl(uri: vscode.Uri): string | undefined { - const extension = vscode.extensions.getExtension('vscode.git') - if (!extension) { - console.warn('Git extension not available') - return undefined - } - if (!extension.isActive) { - console.warn('Git extension not active') - return undefined - } + try { + const extension = vscode.extensions.getExtension('vscode.git') + if (!extension) { + console.warn('Git extension not available') + return undefined + } + if (!extension.isActive) { + console.warn('Git extension not active') + return undefined + } + + const git = extension.exports.getAPI(1) + const repository = git.getRepository(uri) + if (!repository) { + console.warn('No Git repository for URI', uri) + return undefined + } - const git = extension.exports.getAPI(1) - const repository = git.getRepository(uri) - if (!repository) { - console.warn('No Git repository for URI', uri) + return repository.state.remotes[0]?.fetchUrl + } catch (error) { + console.error(error) return undefined } - - return repository.state.remotes[0]?.fetchUrl }