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

Support opening a file in remote but on a different branch

Open xster opened this issue 6 years ago • 9 comments

It's super common to work on a fork of a repo in VSCode but when you want to socialize some discussion around code, you neither want to do it in your fork nor in your current development branch. You typically want to get a link to the current file or current line on the upstream repo's master branch.

Currently, the "Open File on Remote" command always attempts to link to the current working directory's branch regardless of the repo you choose (and your current development branch is unlikely to exist in the upstream repository)

xster avatar Sep 04 '19 20:09 xster

I think both of these use cases are equally common for me. Sometimes I want to open the file on the remote on the current branch, and sometimes I want to open the file on a different branch - usually master.

tom-sherman avatar Aug 19 '20 15:08 tom-sherman

It seems like this option was added in a recent release but AFAICT, there's no setting to choose a default branch when using open file on remote. Could be a nice option to add.

xster avatar Sep 30 '20 17:09 xster

Looks like there's now a "choose default remote" option. Which is great. It's just missing a "choose default remote branch" option :)

xster avatar Nov 23 '20 22:11 xster

The operations I'd like are all on origin, all on master:

"Copy link to file on master" (ignores any selection, just copies the link to the file itself on master with no line number) "Copy permalink to file on master" (if one or more lines are partially selected locally in source, include these in permalink) "Open on master" (if one or more lines are partially selected locally in source, include those in URL to open)

Personally I have never wanted to link to anything other than origin or master. After PRs merge into master, I delete branches so links to non-master feature branches will break. If I want to link to a feature branch, I do that from the PR web UI. That's my workflow, fwiw.

Here is my workaround for now: https://github.com/d4rkr00t/vscode-open-in-github/issues/38

maxh avatar Dec 29 '20 16:12 maxh

Is this now satisfied by the commands:

  • gitlens.openFileRevisionFrom (Open File at Revision From...)
  • gitlens.openFileOnRemoteFrom (Open File on Remote From...)

Possible dupe of #1071 ?

I came looking for this issue because I noticed that openFileOnRemoteFrom seemed to be missing some branches from the quick pick list, even after a recent fetch, although openFileRevisionFrom seems to show these branches.

As it turns out, I prefer opening in VScode (openFileRevisionFrom) rather than opening my browser to look at a different revision (openFileOnRemoteFrom) so I will stick to that – but still seems like a bug from my perspective.

ian-h-chamberlain avatar Mar 18 '21 13:03 ian-h-chamberlain

openFileOnRemoteFrom has solved my use case!

tom-sherman avatar Mar 18 '21 15:03 tom-sherman

I'm having the same issue. I'd like to have Open File on Remote From Default Branch where default branch would be user-configurable - possibly on first usage, and stored in config; or just a simple config variable, defaulting to master / main? (probably simpler to implement)

Open File on Remote From... does not work well for me due to performance issue: we have thousands of branches and tags in the repo, and GitLens first evaluates them all (reading each HEAD to show modification date) before showing the dropdown, which in my case takes ~10s (on MacBookPro!) - waiting 10s each time is clearly not something I want to do :)

jakub-g avatar Jan 20 '22 21:01 jakub-g

Actually Open File on Remote From Default Branch can be implemented very simply, without needing to know what is the default branch: HEAD or - can be used instead of branch name, and it will lead to contents at default branch. (difference is: HEAD will be kept in URL; - will be redirected to actual default branch name).

jakub-g avatar Feb 09 '22 10:02 jakub-g

Is there any issue related to the action when a tag is selected? I tried to filter and search but was unable to find one so far.

In a quick description, my current situation is that when, after selecting menu Open on Remove (Web), I select a tag and not a branch, the URL generated receives a Branch not found

image

I noticed that there is no function that returns a Url for a tag that looks like it is what is missing because I just change GB to GT in Azure DevOps Url and it works as expected.

image

disouzam avatar Feb 02 '24 12:02 disouzam