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 Sign up to answer
How to earn badges on the Atlassian Community

How to earn badges on the Atlassian Community

Badges are a great way to show off community activity, whether you’re a newbie or a Champion.

Learn more
Community showcase
Posted Jun 12, 2018 in Bitbucket

Do you use any Atlassian products for your personal projects?

After spinning my wheels trying to get organized enough to write a book for National Novel Writing Month (NaNoWriMo) I took my affinity for Atlassian products from my work life and decided to tr...

29,163 views 26 12
Join discussion

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