Forums

Articles
Create
cancel
Showing results for 
Search instead for 
Did you mean: 

Cannot get diff in pre-recieve BitBucket Hook

Michael Albers February 4, 2019

I've been working on a BitBucket pre-receive hook plugin for work. This plugin is intended to take the diff for every change and run a custom scanner on the changes, rejecting the commit/edit/etc. if certain things are found. I developed the plugin against 5.14.0 of BitBucket (the default version run by 'atlas-run') and everything went well. At work we use version 5.9.1. When the plugin was installed and enabled there, it started failing.

When getting the diff for a commit, the plugin is failing with the following error:

"Commit 'fba7fdd0ea3be980538fc39d65e3bbe7f46ed3fd' does not exist in repository X" (naturally the commit hash is different.)

I get the same problem in my development environment. Everything is the same except for the version of BitBucket used. I started it with 'atlas-run' and 'atlas-run -v 5.9.1', respectively.

Here is the code I'm using to get the diff for the commits:

GitDiffBuilder diffBuilder = builderFactory.builder(commit.getRepository())
.diff()
.rev(commit.getId())
.contextLines(0);
// Not present if the first commit of a repo.
if (null != ancestor) {
diffBuilder = diffBuilder.ancestor(ancestor.getId());
}

DiffReader diffReader = new DiffReader(); // Custom class to read the diff output
diffBuilder.build(diffReader).call();

 This is being called from the 'onCommitAdded' function of a class implementing the 'PreRepositoryHookCommitCallback' interface.

I've searched online for what I need to do to get the commit diff with no luck.

What do I need to do to get this to work in 5.9.1?

0 answers

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events