Create
cancel
Showing results for 
Search instead for 
Did you mean: 
Sign up Log in

What does "Unexpected output; expected a 'commit' object" mean, for a stash hook?

Dan Rumney July 2, 2013

What does the error

Unexpected output; expected a 'commit' object

mean?

I've created a Stash pre-commit hook. When I try to perform a commit, with my hook enabled, I get

Counting objects: 4, done.
Delta compression using up to 8 threads.
Compressing objects: 100% (2/2), done.
Writing objects: 100% (3/3), 271 bytes, done.
Total 3 (delta 1), reused 0 (delta 0)
remote: Hook com.vodori.hook.PepperFEProtectionHook failed. Error: 
remote: An error occurred while executing an external process: [refs/heads/master]: Unexpected output; expected a 'commit' object
To http://admin@dancrumb-latitude-e6520:7990/stash/scm/project_1/rep_1.git
 ! [remote rejected] master -> master (pre-receive hook declined)
error: failed to push some refs to 'http://admin@dancrumb-latitude-e6520:7990/stash/scm/project_1/rep_1.git'

Clearly, there's an issue with my hook, but I can't find any docs that indicate what that error means, so I don't really know where to start my debug.

Here's my actual code:

public boolean onReceive(RepositoryHookContext context, Collection<RefChange> refChanges, HookResponse hookResponse) {
        Repository repo = context.getRepository();
        Collection<String> changeIDs = new ArrayList<String>(refChanges.size());
        for(RefChange refChange: refChanges) {
            changeIDs.add(refChange.getRefId());
        }
        DetailedChangesetsRequest dcr = new DetailedChangesetsRequest.Builder(repo)
                .changesetIds(changeIDs)
                .ignoreMissing(false)
                .maxChangesPerCommit(9999)
                .build();
        PageRequest pr = new PageRequestImpl(0,9999);
        Page<DetailedChangeset> pg =  historyService.getDetailedChangesets(dcr,pr);
        for (DetailedChangeset dcs: pg.getValues()) {
            for(Change c: dcs.getChanges().getValues()) {
                if(c.getType() == ChangeType.ADD) {
                    String changePath = c.getPath().toString();
                    if(changePath.contains("pepper/pepper") || changePath.contains("pepper/vodori")) {
                        hookResponse.out().println("Kicked it because of " +changePath);
                        return false;
                    }
                }
            }
        }

        return true;
    }

Not asking someone to fix it for me... just help me find the end of the thread so that I can start pulling :)

1 answer

1 accepted

Comments for this post are closed

Community moderators have prevented the ability to post new answers.

Post a new question

1 vote
Answer accepted
Dan Rumney July 2, 2013

I should be using

changeIDs.add(refChange.getToHash());

In line 5... that's the change hash... the refId is "refs/heads/master"

TAGS
AUG Leaders

Atlassian Community Events