Conflicting documentation on hooks

The page "Using repository hooks" ends with the following test:

Git post-receive hooks won't be triggered after a pull request merge. The mechanism that performs the pull request merge is actually based on a git fetch into the repository, which doesn't trigger Git post-receive hooks. If you would like to trigger functionality based on a pull request merge, you should write a post-receive repository hook.

The first sentence says post-receive hook are not triggered by pull request merges. The last sentence says if you want to trigger something based on a pull request merge, you should use a post-receive hook. This seems contradictory.

1 answer

1 accepted

1 vote
Bryan Turner Atlassian Team Jun 29, 2014

Kent,

There's a nasty bit of term overloading in there, but the documentation does actually say what it means. We'll get the documentation cleaned up to make the distinction more obvious, but in the interim let me clarify here what that's really trying to say.

Stash has 2 types of post-receive hook support:

  • Git: PostReceiveHook
  • Repository: AsyncPostReceiveRepositoryHook

Git (PostReceiveHook) hooks are not called for pull request merges, because they are a direct hook down into Git's own post-receive functionality. Git does not invoke post-receive hooks for fetches, so neither does Stash.

Per-repository (AsyncPostReceiveRepositoryHook) hooks are called for pull request merges, because they are just sugar wrapping Stash's RepositoryRefsChangedEvent. A RepositoryPushEvent is a RepositoryRefsChangedEvent, but so is PullRequestMergedEvent (and a host of other things; AsyncPostReceiveRepositoryHook is invoked for pretty much everything).

So, with a little added emphasis: "Git post-receive hooks won't be triggered after a pull request merge. The mechanism that performs the pull request merge is actually based on a git fetchinto the repository, which doesn't trigger Git post-receive hooks. If you would like to trigger functionality based on a pull request merge, you should write a post-receive repository hook."

So, PostReceiveHooks will not be invoked for a pull request merge. If you want to trigger functionality based on pull request merges, you should write an AsyncPostReceiveRepositoryHook.

Hope this helps,
Bryan Turner
Atlassan Stash

I can see the distinctions now. Thanks for clarifying!

Suggest an answer

Log in or Join to answer
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...

710 views 0 4
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
Atlassian Team Tour

Join us on the Team Tour

We're bringing product updates and pro tips on teamwork to ten cities around the world.

Save your spot