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

Commit

Permalink
fix: browser current file respect git root
Browse files Browse the repository at this point in the history
Closes #354
  • Loading branch information
KnisterPeter committed May 9, 2018
1 parent ad3eff7 commit 481f68c
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 2 deletions.
9 changes: 7 additions & 2 deletions src/commands/browse.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import { component } from 'tsdi';
import { component, inject } from 'tsdi';
import * as vscode from 'vscode';

import { TokenCommand } from '../command';
import { Git } from '../git';
import { showProgress } from '../helper';

@component({eager: true})
Expand Down Expand Up @@ -52,6 +53,9 @@ export class BrowseCurrentFile extends TokenCommand {

public id = 'vscode-github.browseCurrentFile';

@inject
private readonly git!: Git;

protected requireProjectFolder = false;

@showProgress
Expand All @@ -62,7 +66,8 @@ export class BrowseCurrentFile extends TokenCommand {
if (!folder) {
return;
}
const file = editor.document.fileName.substring(folder.uri.fsPath.length);
const root = await this.git.getGitRoot(folder.uri);
const file = editor.document.fileName.substring(root.length);
const line = editor.selection.active.line;
const uri = vscode.Uri.parse(await this.workflowManager.getGithubFileUrl(folder.uri, file, line));
vscode.commands.executeCommand('vscode.open', uri);
Expand Down
5 changes: 5 additions & 0 deletions src/git.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,11 @@ export class Git {
}
}

public async getGitRoot(uri: vscode.Uri): Promise<string> {
const response = await this.execute('git rev-parse --show-toplevel', uri);
return response.stdout.trim();
}

public async getRemoteBranches(uri: vscode.Uri): Promise<string[]> {
const response = await this.execute('git branch --list --remotes --no-color', uri);
return response.stdout
Expand Down

0 comments on commit 481f68c

Please sign in to comment.