vscode-gitlens icon indicating copy to clipboard operation
vscode-gitlens copied to clipboard

Improve "open on remote" feature for gerrit/gitiles

Open SanderRonde opened this issue 4 months ago • 0 comments

When using gerrit, when using the "open on remote" feature from the gutter of some line, the line is opened on gitiles. This works really well when you are on the master branch or any other single-word branches. However when you have just used git-review -d, gerrit will create a local branch for you that is (unless a topic is provided in gerrit) named review/{uploader}/{change-number}. When then using "open on remote" you'll navigate to {host}/plugins/gitiles/{project}/+/refs/heads/review/{uploader}/{change-number}/{filepath}. This means a lot of extra slashes are introduced in the URL, leading gitiles to produce a "Cannot parse URL as a Gitiles URL" error.

Specific patches are accessible on gitiles, but by using {host}/plugins/gitiles/{project}/+/refs/changes/{last-2-digits-of-change-number}/{change-number}/{patchset}/{filepath} instead. Any chance the gitlens extension can make that mapping for us when encountering a branch name like the one I mentioned above?

The only hurdle I see is that gitiles wants a patchset number. It's maybe not trivial to find out which patchset the user is on or which one is the latest (I'm not entirely sure how your extension's usage of the gerrit API works, maybe it does know, maybe not). Alternatively gitiles also supports navigating to just a commit. You could always just replace any instance of the above branch name with /plugins/gitiles/{commit-sha}/{filepath} instead and it'll always end up on the latest version of that commit (i.e. latest patchset).

Let me know what you think!

SanderRonde avatar Feb 16 '24 13:02 SanderRonde