@@ -7,7 +7,7 @@ import { URL, URLSearchParams } from 'url';
77import LRUCache from 'lru-cache' ;
88import * as marked from 'marked' ;
99import * as vscode from 'vscode' ;
10- import { Commit , Ref , Remote , Repository } from '../api/api' ;
10+ import { Commit , Ref , Remote , Repository , UpstreamRef } from '../api/api' ;
1111import { GitApiImpl } from '../api/api1' ;
1212import { Protocol } from '../common/protocol' ;
1313import { FolderRepositoryManager , PullRequestDefaults } from '../github/folderRepositoryManager' ;
@@ -405,17 +405,21 @@ async function getUpstream(repository: Repository, commit: Commit): Promise<Remo
405405 let bestRemote : Remote | undefined ;
406406 for ( let branchIndex = 0 ; branchIndex < branchNames . length && ! bestRef ; branchIndex ++ ) {
407407 for ( let remoteIndex = 0 ; remoteIndex < remoteNames . length && ! bestRef ; remoteIndex ++ ) {
408- const remotes = (
409- await repository . getBranches ( {
410- contains : commit . hash ,
411- remote : true ,
412- pattern : `remotes/${ remoteNames [ remoteIndex ] . name } /${ branchNames [ branchIndex ] } ` ,
413- count : 1 ,
414- } )
415- ) . filter ( value => value . remote && value . name ) ;
416- if ( remotes && remotes . length > 0 ) {
417- bestRef = remotes [ 0 ] ;
418- bestRemote = remoteNames [ remoteIndex ] . remote ;
408+ try {
409+ const remotes = (
410+ await repository . getBranches ( {
411+ contains : commit . hash ,
412+ remote : true ,
413+ pattern : `remotes/${ remoteNames [ remoteIndex ] . name } /${ branchNames [ branchIndex ] } ` ,
414+ count : 1 ,
415+ } )
416+ ) . filter ( value => value . remote && value . name ) ;
417+ if ( remotes && remotes . length > 0 ) {
418+ bestRef = remotes [ 0 ] ;
419+ bestRemote = remoteNames [ remoteIndex ] . remote ;
420+ }
421+ } catch ( e ) {
422+ // continue
419423 }
420424 }
421425 }
@@ -450,11 +454,11 @@ export interface PermalinkInfo {
450454}
451455
452456function getSimpleUpstream ( repository : Repository ) {
453- if ( repository . state . HEAD ?. upstream ) {
454- for ( const remote of repository . state . remotes ) {
455- if ( repository . state . HEAD . upstream . remote === remote . name ) {
456- return remote ;
457- }
457+ const upstream : UpstreamRef | undefined = repository . state . HEAD ?. upstream ;
458+ for ( const remote of repository . state . remotes ) {
459+ // If we don't have an upstream, then just use the first remote.
460+ if ( ! upstream || ( upstream . remote === remote . name ) ) {
461+ return remote ;
458462 }
459463 }
460464}
0 commit comments