How can I check the branch name in preUpdate hook

Hello!

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.

Hi,

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.

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

Yea, this was helpful! Thank you for sharing!