@@ -7,7 +7,7 @@ import { URL, URLSearchParams } from 'url';
7
7
import LRUCache from 'lru-cache' ;
8
8
import * as marked from 'marked' ;
9
9
import * as vscode from 'vscode' ;
10
- import { Commit , Ref , Remote , Repository } from '../api/api' ;
10
+ import { Commit , Ref , Remote , Repository , UpstreamRef } from '../api/api' ;
11
11
import { GitApiImpl } from '../api/api1' ;
12
12
import { Protocol } from '../common/protocol' ;
13
13
import { FolderRepositoryManager , PullRequestDefaults } from '../github/folderRepositoryManager' ;
@@ -405,17 +405,21 @@ async function getUpstream(repository: Repository, commit: Commit): Promise<Remo
405
405
let bestRemote : Remote | undefined ;
406
406
for ( let branchIndex = 0 ; branchIndex < branchNames . length && ! bestRef ; branchIndex ++ ) {
407
407
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
419
423
}
420
424
}
421
425
}
@@ -450,11 +454,11 @@ export interface PermalinkInfo {
450
454
}
451
455
452
456
function 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 ;
458
462
}
459
463
}
460
464
}
0 commit comments