Skip to content
This repository was archived by the owner on Nov 27, 2023. It is now read-only.

Commit 481f68c

Browse files
committed
fix: browser current file respect git root
Closes #354
1 parent ad3eff7 commit 481f68c

2 files changed

Lines changed: 12 additions & 2 deletions

File tree

src/commands/browse.ts

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
1-
import { component } from 'tsdi';
1+
import { component, inject } from 'tsdi';
22
import * as vscode from 'vscode';
33

44
import { TokenCommand } from '../command';
5+
import { Git } from '../git';
56
import { 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);

src/git.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff 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

0 commit comments

Comments
 (0)