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.

Regards,

Anil

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.

Regards

Anil

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.

Regards

Anil

Suggest an answer

Log in or Sign up to answer
Atlassian Community Anniversary

Happy Anniversary, Atlassian Community!

This community is celebrating its one-year anniversary and Atlassian co-founder Mike Cannon-Brookes has all the feels.

Read more
Community showcase
Piotr Plewa
Published Dec 27, 2017 in Bitbucket

Recipe: Deploying AWS Lambda functions with Bitbucket Pipelines

Bitbucket Pipelines helps me manage and automate a number of serverless deployments to AWS Lambda and this is how I do it. I'm building Node.js Lambda functions using node-lambda&nbsp...

1,737 views 1 5
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