How do you do pre-commit hooks in Stash?

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

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.

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.

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

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?

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.

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

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

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
Community showcase
Published Nov 06, 2018 in Bitbucket

Upgrade Best Practices

Hello! My name is Mark Askew and I am a Premier Support Engineer for products Bitbucket Server/Data Center, Fisheye & Crucible. Today, I want to bring the discussion that Jennifer, Matt, and ...

422 views 5 9
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