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(
575575 if ( ! folderManager ) {
576576 return { permalink : undefined , error : 'Current file does not belong to an open repository.' , originalFile : undefined } ;
577577 }
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+ }
579585 const upstream = getSimpleUpstream ( folderManager . repository ) ;
580586 if ( ! upstream ?. fetchUrl ) {
581587 return { permalink : undefined , error : 'Repository does not have any remotes.' , originalFile : undefined } ;
582588 }
583589 const pathSegment = uri . path . substring ( folderManager . repository . rootUri . path . length ) ;
584590 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
586592 } ${ pathSegment } ${ rangeString ( range ) } `,
587593 error : undefined ,
588594 originalFile : uri
You can’t perform that action at this time.
0 commit comments