It's not the same without you

Join the community to find out what other Atlassian users are discussing, debating and creating.

Atlassian Community Hero Image Collage

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

Dan Rumney Jul 02, 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

1 vote
Answer accepted
Dan Rumney Jul 02, 2013

I should be using

changeIDs.add(refChange.getToHash());

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

Suggest an answer

Log in or Sign up to answer
This widget could not be displayed.
This widget could not be displayed.
Community showcase
Posted in Statuspage

⭐️Would you recommend Statuspage? Leave a (honest!) review. ⭐️

Hi Community friends, We're working on sourcing more reviews on Capterra – a popular software review site –  to help teams like yours make more informed decisions when choosing an inc...

96 views 3 5
Join discussion

Community Events

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

Find an event

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

Unfortunately there are no Community Events near you at the moment.

Host an event

You're one step closer to meeting fellow Atlassian users at your local event. Learn more about Community Events

Events near you