Issue with local/feature branch

Hi All,

I am facing...Can you please suggest me something to acheiving this,

Problem : Suppose one branch in GIT saying that DEV1 and administrator committed some files and pushed the same to server.

I have also checkout the same branch and worked something on it and committed the message locally but I am not able to push my work directly on server because I dont have permission for that. So I have created local branch on DEV1 and pushed the same.

I wrote HOOK which take care of commit message which is in pre-defined format in regular expression. If committed message match then user can push there code otherwise hook will reject the push.

My problem is, when we create the local branch i want to read only those commit message which I added after administrator change but it is returning all the commit messages which is already committed by administator in DEV1.

We are using below code snippets in pre-HOOK,


public boolean onReceive(RepositoryHookContext context, Collection<RefChange> refChanges, HookResponse hookResponse)


for (RefChange refChange : refChanges)


ChangesetsBetweenRequest request = new ChangesetsBetweenRequest.Builder( context.getRepository()).exclude(refChange.getFromHash()) .include(refChange.getToHash()).build();

final Page<Changeset> cs = commitService.getChangesetsBetween( request, PAGE_REQUEST);

for (Changeset changeset : cs.getValues()) {

commit_msg = changeset.getMessage();




Please suggest me how can we read the latest commit messages.

I want to read the localcommits , I dont want to read the pushed commits. How can I achieve it.



1 answer

You can detect commits which do not already exist on the server like this (changesetIndex is this class):

for(Changeset changeset: cs.getValues())
    //false for new commits, true for old ones
    if (!changesetIndex.isMemberOf(changeset.getId(), repository))
        //do stuff

Hi Balazs thanks for the suggestion , its worked.

And in one scenario, i.e., If I create any branch and without commit anything If I push the empty branch then the branch should push to server or it shouldn't.



Still I have this doubt..can we allow empty branch to push to server or not..

What is wrong with empty branches?

I'm checking for commit message whether the commit message having valid ticket number or not. Able to do it with pre-hook.

Now, If I created a new branch then from Hash Id getting "00000000000000....000". It is trying to read all the changesets.

I restricted to do work with only local-commits other than pushed ones with isMember( ) method (This is of your suggested method in other threads).

Is there any check whether the brancch pushed with changes or empty changes so that. If the empty branch pushed il just allow it to push other than the other stufff which I'm doing.



Suggest an answer

Log in or Sign up to answer
Community showcase
Published Nov 06, 2018 in Bitbucket

Upgrade Best Practices

Hello! My name is Mark Askew and I am a Premier Support Engineer for products Bitbucket Server/Data Center, Fisheye & Crucible. Today, I want to bring the discussion that Jennifer, Matt, and ...

657 views 5 9
Read article

Atlassian User Groups

Connect with like-minded Atlassian users at free events near you!

Find a group

Connect with like-minded Atlassian users at free events near you!

Find my local user group

Unfortunately there are no AUG chapters near you at the moment.

Start an AUG

You're one step closer to meeting fellow Atlassian users at your local meet up. Learn more about AUGs

Groups near you