1

Some shops mandate checking in long, autogenerated files into source control that clutter up BitBucket pull request pages with large diffs, leaving you to scroll epic distances or depend on the top navigation to visit files key to a code review.

Despite at least three different tickets dating back to 2014 asking Atlassian to support excluding specific file diffs from pull request pages, a John Garcia explained why they would not implement this feature:

This response is reasonable for the referenced case, yet unhelpful to users as a whole. Even if the people referenced in the conversation were using source control inappropriately by tracking files that they should not track, others reviewing code might not be in a position to change that. Then there are big (as in, often has diffs that take up at least one screen) autogenerated files that frequently change, aren't normally worth reading and should be in source control, such as yarn.lock. Citing a StackOverflow answer addressing one case with 11 votes at the time of this writing does not make the feature request unjustified.

I had the same problem as the people supporting the ticket (with many yarn.lock files, no less) so I wrote a userscript creatively named "Hide Annoying BitBucket Diffs (HABD)." It's set to execute when you view a pull-request page powered by BitBucket. The script does not support binary files. Installation instructions are at the bottom of this article.

In order for this script to function, you will need to configure a couple of things. Thankfully it's quick!

You can control what diffs to remove by referencing a plain text resource listing one regular expression per line (Pointing to a raw Pastebin helps here). A diff is removed from the pull request page if the filename corresponding to that diff matches ANY of the expressions in the resource. 

For example, this resource hides file diff blocks for package.json and yarn.lock, both of which are common in Node projects and are checked into source control.

package.json$
yarn.lock$

If we're clear up to this point and you want to use the script, let's get you set up. If you encounter any problems, please report an issue.

Script installation for TamperMonkey

  1. While using Chrome, add TamperMonkey.
  2. Go to HABD's page on OpenUserJs.org and click "Install." You will see the source code and a confirmation. Confirm the installation.
  3. Click the Tampermonkey icon in Chrome and click "Dashboard." You will see a list of installed scripts.
  4. At the far right of the row where you see HABD, you will see a little notepad icon. Click that to edit the script.
  5. Change the line starting with "@resource" to point to a raw PasteBin or some other clear text resource with one regular expression per line. The link already in the script points to an example. Remember that the regular expressions match against filenames. If ANY of the expressions match, the diff is removed from the page.
  6. (Optional) Change the line starting with "@match" so that it matches only the pages in which you review BitBucket pull requests.
  7. (Optional) If you want to hide diffs on both pull request and commit pages, use the @include rule to add another URL matching pattern.

Script installation for GreaseMonkey

  1. While using Firefox (or some other supported browser), add GreaseMonkey.
  2. Go to HABD's page on OpenUserJs.org and click "Install." You will see the source code and a confirmation. Confirm the installation.
  3. Click the arrow next to the GreaseMonkey icon in Firefox and click "Manage User Scripts." You will see a list of installed scripts.
  4. On the row for "Hide Annoying Bitbucket Diffs", click "Preferences," then "Edit This User Script."
  5. Change the line starting with "@resource" to point to a raw PasteBin or some other clear text resource with one regular expression per line. The link already in the script points to an example. Remember that the regular expressions match against filenames. If ANY of the expressions match, the diff is removed from the page.
  6. (Optional) Change the line starting with "@match" so that it matches only the pages in which you review BitBucket pull requests.
  7. (Optional) If you want to hide diffs on both pull request and commit pages, use the @include rule to add another URL matching pattern.