Skip to content

Add project.currentBranch and file.currentHash to URL context #185

@vergenzt

Description

@vergenzt

Use case: I'd like to be able to open the Github blame URL for the current version of the file I'm looking at. The URL for this needs the current hash of the file you're looking at (or the current branch containing that file).

Example

If I'm looking at the following line in VSCode:

for (const fileName of this.files.keys()) {

I'd love to be able to produce the following link:

https://github.com/Sertion/vscode-gitblame/blame/bb98406ab8837d506fb3b69e0a3147a06fbf0790/src/git/blame.ts#L115

Unfortunately, ${hash} when generating the URL for that line is correctly d220cd7 (i.e. the commit which touched that line), but the line number may only be accurate as of the current commit (i.e. bb98406).

My first attempt at getting the blame URL was to set gitblame.commitUrl to ${tool.protocol}//${gitorigin.hostname}${gitorigin.port}${gitorigin.path}/blame/${hash}/${file.path}#L${file.line}. This is incorrect as described below though, and results in the following URL:

https://github.com/Sertion/vscode-gitblame/blame/d220cd765dbe9f2661fd6e032c0dbfd05b0362d0/src/git/blame.ts#L115

which as of that version of the file the line number is now a completely different line 🙁

const gitRoot = getGitFolder(fileName);

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions