Create
cancel
Showing results for 
Search instead for 
Did you mean: 
Sign up Log in

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
Jens Schumacher [Atlassian]
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
May 18, 2012

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 December 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
Jens Schumacher [Atlassian]
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
March 5, 2013

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

1 vote
jhinch (Atlassian)
Atlassian Team
Atlassian Team members are employees working across the company in a wide variety of roles.
December 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.

0 votes
Jorge Costa June 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

0 votes
Mike Eldridge March 3, 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 March 3, 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
Scott Hutchinson February 5, 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 March 3, 2013

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

jhinch (Atlassian)
Atlassian Team
Atlassian Team members are employees working across the company in a wide variety of roles.
March 3, 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
Chih-Kuo, Hu July 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
Atlassian Team
Atlassian Team members are employees working across the company in a wide variety of roles.
July 17, 2012

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

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events