How can I check the branch name in preUpdate hook


I have preUpdate hook, that checks several restrictions. When needed it will reject the push. Something like:
public RepositoryHookResult preUpdate(@Nonnull PreRepositoryHookContext preRepositoryHookContext, @Nonnull RepositoryHookRequest repositoryHookRequest) {

return RepositoryHookResult. accepted (); // or rejected

But I would like it to apply those restrictions only for Master branch. Any idea how can I check the branch name?

Thanks in advance.


it should be possible to check the branch name with something like this:

repositoryHookRequest.getRefChanges().forEach(refChange -> {
    if ("refs/heads/master".equals(refChange.getRef().getId())) {
        // this is it

Please let me know if this helped you.

Vojtěch Schlemmer [MoroSystems, s.r.o., Czech Republic]

Yea, this was helpful! Thank you for sharing!

If it is a solution to your problem, could you please mark it as solution? It will help the future readers. Thanks.