@@ -345,28 +345,37 @@ export class ReviewManager extends Disposable {
345
345
return false ;
346
346
}
347
347
348
- private async getUpstreamUrlAndName ( branch : Branch ) : Promise < { url : string | undefined , branchName : string | undefined , remoteName : string | undefined } > {
348
+ private async getUpstreamUrlAndName ( branch : Branch ) : Promise < { remoteUrl : string | undefined , upstreamBranchName : string | undefined , remoteName : string | undefined } > {
349
349
if ( branch . upstream ) {
350
- return { remoteName : branch . upstream . remote , branchName : branch . upstream . name , url : undefined } ;
350
+ Logger . debug ( `Upstream for branch ${ branch . name } is ${ branch . upstream . remote } /${ branch . upstream . name } ` , this . id ) ;
351
+ return { remoteName : branch . upstream . remote , upstreamBranchName : branch . upstream . name , remoteUrl : undefined } ;
351
352
} else {
352
353
try {
353
- const url = await this . repository . getConfig ( `branch.${ branch . name } .remote` ) ;
354
+ const remoteUrl = await this . repository . getConfig ( `branch.${ branch . name } .remote` ) ;
354
355
const upstreamBranch = await this . repository . getConfig ( `branch.${ branch . name } .merge` ) ;
355
- let branchName : string | undefined ;
356
+ let upstreamBranchName : string | undefined ;
356
357
if ( upstreamBranch ) {
357
- branchName = upstreamBranch . substring ( 'refs/heads/' . length ) ;
358
+ upstreamBranchName = upstreamBranch . substring ( 'refs/heads/' . length ) ;
358
359
}
359
- return { url, branchName, remoteName : undefined } ;
360
+ Logger . debug ( `Upstream for branch ${ branch . name } is ${ upstreamBranchName } at ${ remoteUrl } ` , this . id ) ;
361
+ return { remoteUrl : remoteUrl , upstreamBranchName, remoteName : undefined } ;
360
362
} catch ( e ) {
361
363
Logger . appendLine ( `Failed to get upstream for branch ${ branch . name } from git config.` , this . id ) ;
362
- return { url : undefined , branchName : undefined , remoteName : undefined } ;
364
+ return { remoteUrl : undefined , upstreamBranchName : undefined , remoteName : undefined } ;
363
365
}
364
366
}
365
367
}
366
368
367
369
private async checkGitHubForPrBranch ( branch : Branch ) : Promise < ( PullRequestMetadata & { model : PullRequestModel } ) | undefined > {
368
- const { url, branchName, remoteName } = await this . getUpstreamUrlAndName ( this . _repository . state . HEAD ! ) ;
369
- const metadataFromGithub = await this . _folderRepoManager . getMatchingPullRequestMetadataFromGitHub ( branch , remoteName , url , branchName ) ;
370
+
371
+ let branchToCheck : Branch ;
372
+ if ( this . _repository . state . HEAD && ( branch . name === this . _repository . state . HEAD . name ) ) {
373
+ branchToCheck = this . _repository . state . HEAD ;
374
+ } else {
375
+ branchToCheck = branch ;
376
+ }
377
+ const { remoteUrl : url , upstreamBranchName, remoteName } = await this . getUpstreamUrlAndName ( branchToCheck ) ;
378
+ const metadataFromGithub = await this . _folderRepoManager . getMatchingPullRequestMetadataFromGitHub ( branchToCheck , remoteName , url , upstreamBranchName ) ;
370
379
if ( metadataFromGithub ) {
371
380
Logger . appendLine ( `Found matching pull request metadata on GitHub for current branch ${ branch . name } . Repo: ${ metadataFromGithub . owner } /${ metadataFromGithub . repositoryName } PR: ${ metadataFromGithub . prNumber } ` , this . id ) ;
372
381
await PullRequestGitHelper . associateBranchWithPullRequest (
0 commit comments