Issue with local/feature branch

anil kumar May 12, 2014

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

1 vote
Balázs Szakmáry
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
May 13, 2014

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
    }
}

anil kumar May 14, 2014

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

anil kumar May 25, 2014

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

Balázs Szakmáry
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
May 25, 2014

What is wrong with empty branches?

anil kumar May 25, 2014

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
TAGS
AUG Leaders

Atlassian Community Events