Reject one ref update

Hello,

I’m looking at the new hooks API now and wonder whether it is possible to reject one ref update of many, e.g. in a case when push updates multiple references and I would like to reject only some of the ref updates? Similar to what one could do with the Git update hook?

From the first glance it looks like that is not possible - complete push is either accepted or rejected. Might I miss something?

Thanks!

Alexander Kitaev.

Hi Alexander,

Bitbucket Server’s Hooks API integrates with git’s pre-receive and post-receive hooks, but not with the update hook (for performance reasons). As a result, it’s only possible to accept/reject the push as a whole.

Hope that clarifies things!

Cheers,
Michael

Hello Michael,

thank you for reply! Would you consider extending RepositoryHookResult or RepositoryHookVeto classes to let hook implementation provide composite result with some ref changes accepted and some rejected? I think this shouldn’t affect performance, at least no new hook will be introduced.

Thanks once again for reply!
Alexander.

Short answer: if you mean to actually allow some of the refs to be updated, no. You can however already provide multiple veto messages if you want to provide details about each of the problematic refs. Just create a RepositoryHookResult.Builder and call veto on it multiple times.

More detailed explaination:
Since we only integrate with git’s pre-receive and post-receive hooks, that’s not an option. The git pre-receive hook only allow you to either accept or reject all refs.

To be able to reject only some refs, we’d have to integrate with git’s update hook, which would mean a separate callback from git into Bitbucket Server for each ref that’s updated. That has some implications in terms of performance: many hooks need to retrieve some commit or diff data. This can more efficiently be retrieved (in less git calls) when done for all refs in batch. Per-ref callbacks would result in more overhead in getting information about the proposed change. Add to this the overhead in the git -> Bitbucket Server integration itself. The cost would add up and the system would feel sluggish when pushing multiple refs.