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

How do you do pre-commit hooks in Stash?

Bernard O'Flynn May 17, 2012

Can you just use git's usual pre-commit hooks?

Or do you have to do something special in stash to allow this?

8 answers

1 accepted

2 votes
Answer accepted

We will implement hooks in a future release of Stash. You can find the issue under the following URL:

https://jira.atlassian.com/browse/STASH-2521

That being said, you can still install git's usual hooks on disk. There is just no nice UI for it in Stash right now that makes it easier to maintain these hooks.

Garret Pick Dec 12, 2012

Hi,

A follow-up question on this topic. I'm running Stash 2.0. In my .git/hooks directory, there is already a pre-receive file with the following content:

#!/bin/bash
#>*******************************************************
# THIS FILE WAS AUTO-GENERATED BY ATLASSIAN STASH.
# DO NOT MODIFY UNDER ANY CIRCUMSTANCE.
#>*******************************************************
exec $STASH_HOOK_COORDINATOR hooks/pre-receive.d "$@" <&0 >&1 2>&2

What is the recommended way to add additional hooks (until the feature is ready)?

Should I just create an executable script in the pre-receive.d subdirectory - in addition to 20_stash_callback that is already there?

#!/bin/bash
#>*******************************************************
# THIS FILE WAS AUTO-GENERATED BY ATLASSIAN STASH.
# DO NOT MODIFY UNDER ANY CIRCUMSTANCE.
#>*******************************************************
exec $STASH_HOOK_CALLBACK git-pre-receive "$@" <&0 >&1 2>&2

1 vote
Jason Hinch Atlassian Team Dec 12, 2012

In Stash 2.0 you can create a script in the <STASH_HOME>/data/repositories/<REPO_ID>/hooks/pre-receive.d directory. There should already be a script in there which Stash uses as a callback from git. Don't modify this one but create a new one along side it. The scripts in this directory should be prefixed with a number which indicates the order which the scripts will be executed.

1 vote

Stash now supports pre and post-receive hooks out of the box: http://blogs.atlassian.com/2013/03/stash-22-customize-workflow-git-hooks-api-merge-checks

0 votes
Chih-Kuo, Hu Jul 17, 2012

I am using Stash in my company, but we would like to have such pre-commit hook to control evey push must has correspondind open ticket in Jira, when will you release this feature in future? or you have any idea or you can introduce some extension plug-in I can use, thanks

Seb Ruiz Atlassian Team Jul 17, 2012

You can add a git commit hook by navigating to the repository location and adding a script to the hooks directory

0 votes
Scott Hutchinson Feb 05, 2013

Can anyone provide an example filename, and file contents to reproduce what Jason describred?

I can create files in: <STASH_HOME>/data/repositories/<REPO_ID>/hooks/pre-receive.d but I'm not sure exactly how each hook is being accessed by Stash.

Once I have the proper filename and contents, will a fresh clone of the repo now contain my commit hook?

Mike Eldridge Mar 03, 2013

Scott, those files aren't touched by Stash at all. Those hooks are git hooks. You can read more about them here:

Jason Hinch Atlassian Team Mar 03, 2013

Commit hooks are not transfered when you clone a repository. They are always specific to a particular clone. pre-receive hooks aren't really relevant to local copies of a repository as they only get triggered when someone pushed to a repository, not when you fetch or commit to a repository.

0 votes
Mike Eldridge Mar 03, 2013

Scott, those files aren't touched by Stash at all. Those hooks are git hooks. You can read more about them here: http://git-scm.com/book/en/Customizing-Git-Git-Hooks

0 votes
Mike Eldridge Mar 03, 2013

Scott, those files aren't touched by Stash at all. Those hooks are git hooks. You can read more about them here: http://git-scm.com/book/en/Customizing-Git-Git-Hooks

0 votes
Jorge Costa Jun 20, 2013

Sorry for reviving this thread, but its the only one I found on the subject.

I got stash to email me my commits, but my emails are arriving without the repo name/project information.

"

This is an automated email from the git hooks/post-receive script. It was
generated because a ref change was pushed to the repository containing
the project "UNNAMED PROJECT".
"

Using the default hook,

99_post-receive-email -> /usr/share/git-core/contrib/hooks/post-receive-email

Suggest an answer

Log in or Sign up to answer
This widget could not be displayed.
This widget could not be displayed.
Community showcase
Published in Bitbucket Pipelines

Building a Bitbucket Pipe as a casual coder

...ipe.sh :  #!/bin/bash source "$(dirname "$0")/common.sh" enable_debug extra_args="" if [[ "${DEBUG}" == "true" ]]; then extra_args="--verbose" fi # mandatory variables R...

3,085 views 1 20
Read article

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