Conflicting documentation on hooks

Kent Rollins June 29, 2014

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
Answer accepted
Bryan Turner
Atlassian Team
Atlassian Team members are employees working across the company in a wide variety of roles.
June 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

Kent Rollins June 29, 2014

I can see the distinctions now. Thanks for clarifying!

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events