This repository was archived by the owner on Nov 27, 2023. It is now read-only.
File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1- import { component } from 'tsdi' ;
1+ import { component , inject } from 'tsdi' ;
22import * as vscode from 'vscode' ;
33
44import { TokenCommand } from '../command' ;
5+ import { Git } from '../git' ;
56import { showProgress } from '../helper' ;
67
78@component ( { eager : true } )
@@ -52,6 +53,9 @@ export class BrowseCurrentFile extends TokenCommand {
5253
5354 public id = 'vscode-github.browseCurrentFile' ;
5455
56+ @inject
57+ private readonly git ! : Git ;
58+
5559 protected requireProjectFolder = false ;
5660
5761 @showProgress
@@ -62,7 +66,8 @@ export class BrowseCurrentFile extends TokenCommand {
6266 if ( ! folder ) {
6367 return ;
6468 }
65- const file = editor . document . fileName . substring ( folder . uri . fsPath . length ) ;
69+ const root = await this . git . getGitRoot ( folder . uri ) ;
70+ const file = editor . document . fileName . substring ( root . length ) ;
6671 const line = editor . selection . active . line ;
6772 const uri = vscode . Uri . parse ( await this . workflowManager . getGithubFileUrl ( folder . uri , file , line ) ) ;
6873 vscode . commands . executeCommand ( 'vscode.open' , uri ) ;
Original file line number Diff line number Diff line change @@ -33,6 +33,11 @@ export class Git {
3333 }
3434 }
3535
36+ public async getGitRoot ( uri : vscode . Uri ) : Promise < string > {
37+ const response = await this . execute ( 'git rev-parse --show-toplevel' , uri ) ;
38+ return response . stdout . trim ( ) ;
39+ }
40+
3641 public async getRemoteBranches ( uri : vscode . Uri ) : Promise < string [ ] > {
3742 const response = await this . execute ( 'git branch --list --remotes --no-color' , uri ) ;
3843 return response . stdout
You can’t perform that action at this time.
0 commit comments