Copy GitLab link for the active file to the clipboard - permalink vs master
Problem to solve
I used to share files (mainly markdown notes) stored in a git repository in GitLab.com with colleagues. I found this really useful especially for people "outside" GitLab itself (when project is public, of course)
Unfortunately, with standard Copy Link to Active File in GitLab
command you got
- permalink
- the current line position selected
The former is annoying when your documentation is in progress and you would like people to reference to latest main
version (or maybe a specific branch)
The latter force GitLab showing the Markdown source code instead of rendered page
I'm used to:
- run
Copy Link to Active File in GitLab
command - paste link
- change permalink SHA to
main
(ormaster
.. and I always mistake this😅 ) - remove trailing line reference
Proposal
Split the existing GitLab: Copy Link to active file
to two commands:
GitLab: Copy Link to active file (permalink)
GitLab: Copy Link to active file (current branch)
This will allow the user to pick which option they want.
For starters, let's not remove the line range fragment, we can do that in future iterations.
Original great proposal from @andreascian
So, I suggest to have:
- either a configuration option for link sharing (permalink or not, with/without line number)
- or additional command, e.g.
-
GitLab: Copy Link to active file
, which is the currentpermalink
implementation (will it be useful to specify asGitLab: Copy Link to active file (permalink)
? -
GitLab: Copy Link to active file (current branch)
. Line number here does not make sense IMHO
-
Implementation notes
follow the CONTRIBUTING.md to setup the project, find out more about our testing and architecture in docs/dev
folder.
- The command is defined in
desktop.package.json
https://gitlab.com/gitlab-org/gitlab-vscode-extension/blob/a615ceff8c7c591f3132a104b1768371249eff2b/desktop.package.json#L49-53 - You can full text search the
gl.copyLinkToActiveFile
to find the constant https://gitlab.com/gitlab-org/gitlab-vscode-extension/blob/a615ceff8c7c591f3132a104b1768371249eff2b/src/desktop/command_names.ts#L12 - and following the constant you'll see that we register the command in the
extension.ts
file https://gitlab.com/gitlab-org/gitlab-vscode-extension/blob/a615ceff8c7c591f3132a104b1768371249eff2b/src/desktop/extension.ts#L119 - That leads you to the top-level function of the command https://gitlab.com/gitlab-org/gitlab-vscode-extension/blob/a615ceff8c7c591f3132a104b1768371249eff2b/src/desktop/commands/openers.ts#L114-117
- be aware that the
getActiveFile
function is reused for two commands, copying the link and opening it in the browser https://gitlab.com/gitlab-org/gitlab-vscode-extension/blob/a615ceff8c7c591f3132a104b1768371249eff2b/src/desktop/commands/openers.ts#L74 - this is were we insert the SHA ref in to the link https://gitlab.com/gitlab-org/gitlab-vscode-extension/blob/a615ceff8c7c591f3132a104b1768371249eff2b/src/desktop/commands/openers.ts#L95
- if you want to add an option to use the ref, see the MR that replaced current branch with permalink: !746 (merged)
- It's important to realise, you don't necessarily want to use the local branch, you want to use the tracking branch because the remote name doesn't have to be the same !746 (diffs)
Further details
I think that directly allow to:
- use current branch instead of permalink
- avoid reference to specific line
may help also others and improve this (really useful, IMHO) functionality
Links / references
- this is related to #209 (closed) and especially to this comment
- maybe the first version of this command was not permalink and something changed during development
🤔