File tree Expand file tree Collapse file tree 1 file changed +8
-2
lines changed Expand file tree Collapse file tree 1 file changed +8
-2
lines changed Original file line number Diff line number Diff line change @@ -575,14 +575,20 @@ export async function createGitHubLink(
575
575
if ( ! folderManager ) {
576
576
return { permalink : undefined , error : 'Current file does not belong to an open repository.' , originalFile : undefined } ;
577
577
}
578
- const defaults = await folderManager . getPullRequestDefaults ( ) ;
578
+ let branchName = folderManager . repository . state . HEAD ?. name ;
579
+ if ( ! branchName ) {
580
+ // Fall back to default branch name if we are not currently on a branch
581
+ const origin = await folderManager . getOrigin ( ) ;
582
+ const metadata = await origin . getMetadata ( ) ;
583
+ branchName = metadata . default_branch ;
584
+ }
579
585
const upstream = getSimpleUpstream ( folderManager . repository ) ;
580
586
if ( ! upstream ?. fetchUrl ) {
581
587
return { permalink : undefined , error : 'Repository does not have any remotes.' , originalFile : undefined } ;
582
588
}
583
589
const pathSegment = uri . path . substring ( folderManager . repository . rootUri . path . length ) ;
584
590
return {
585
- permalink : `https://github.com/${ new Protocol ( upstream . fetchUrl ) . nameWithOwner } /blob/${ defaults . base
591
+ permalink : `https://github.com/${ new Protocol ( upstream . fetchUrl ) . nameWithOwner } /blob/${ branchName
586
592
} ${ pathSegment } ${ rangeString ( range ) } `,
587
593
error : undefined ,
588
594
originalFile : uri
You can’t perform that action at this time.
0 commit comments