Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Link to specific line(s) of code in stash / bitbucket?

With github we can use URLs of the form

www.github.com/username/repo/filename.c#L20-L45

Note the #L20-L45 at the end which highlights the 20th to 45th lines of code when the page loads in the browser.

This convention doesn't appear to work the same way in stash / bitbucket - is it possible to link to certain lines of code somehow?

like image 637
stevec Avatar asked Jan 15 '20 00:01

stevec


People also ask

How do I link to a specific line in Bitbucket?

In the source file, to select multiple lines of code hold shift or command and click row numbers you want to select. then you can copy the browser URL and share it.

How do I search for a line of code in Bitbucket?

To start searching in Bitbucket, select the search field in the upper-right corner of the top navigation bar, then enter either a single word or an entire phrase (in double quotes). The keyboard shortcut to start a search from anywhere in Bitbucket is " / ".

How do I add a code snippet to Bitbucket?

Paste some code or drag a file onto the page. Select the owner of the snippet from Create in menu. Set the permissions to either public or private. Click Create snippet.

How do you send a repository link in Bitbucket?

On the “Overview” page, on the right side, click “Invite users to this repo”. If your friend register in step 1, enter his user name, otherwise just enter the email and he will get a mail with a link to register. Afterwards, your friend will have access to your repository using his own Bitbucket credentials.


2 Answers

In BitBucket, an URL should end with #lines-x:y

Example:

https://bitbucket.org/stangenberg/docker-docker/src/1ac537b84855db2cc5ee0caf31c782900e094d8e/docker.sh#lines-13:15

Regarding Stash (now 2019+ renamed BitBucket Server), Stash 3.8 in 2015 is supposed to support deep linking with multiline selection. Issue BSERV-2477

With just shift+click, a developer can select a range of lines, then add separate lines to the selection with command+click (or control+click), then copy the URL and share their selection with other developers.

https://info.seibert-media.net/download/attachments/11113140/Stash-38.png?version=1&modificationDate=1474904524000&api=v2

The OP confirms in the comments:

The stash url generated has #13-15 at the end, i.e. it is of the form:

https://bitbucket.org/stangenberg/docker-docker/src/1ac537b84855db2cc5ee0caf31c782900e094d8e/docker.sh#13-15

As cellepo notes in the comments:

  • this cannot be done in a pull request/code-review page (https://bitbucket.../pull-requests/...),
    but
  • it CAN be done on a source page (https://bitbucket.../src/...) like in the aforementioned example URL.
like image 90
VonC Avatar answered Sep 16 '22 20:09

VonC


It appears to me that there may be different syntax for the the url lines ending, maybe according to different Bitbucket version...

@VonC Answer is good - I think it worked for me before, but apparently it does not for me anymore, and I'm guessing different BitBucket version may make the difference..

Whatever the reason for the difference, if @VonC Answer does not work for you, try this (emphasis on #7-8):

bitbucket.your.domain/.../your/project/structure/.../yourfile.filetype#7-8

The UI rendering of that is a bit different from @VonC linked example - just blue highlighting of line-number gutter (instead of yellow highlighting of code):

enter image description here That rendering looks looks identical to that from @VonC for [non-contiguous] multiline selection - and in my Bitbucket version, non-contiguous selection with CMD + click similarly works (as below - emphasis on ,10,12)

bitbucket.your.domain/.../your/project/structure/.../yourfile.filetype#7-8,10,12
like image 40
cellepo Avatar answered Sep 20 '22 20:09

cellepo