Missed Team ’24? Catch up on announcements here.

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

How does it create a new repository?

Murtaza Pitalwala December 16, 2013

Hello,

This questions is regarding Atlassian Stash.

When I click on create repository inside (for example Test project), it creates a repo directory inside [Stash Install]/data/repositories and numbers it. For example if 'test1' is my first repository directory, it would create [Stash Install]/data/repositories/1; then, it would create following files and directories inside [Stash Install]/data/repositories/1.

branches (dir)

config (file)

description (file)

HEAD (file)

hooks (dir)

info (dir)

objects (dir)

refs (dir)

Now, my questions are following:

1. when it is creating those files and directories, does it copy files under hooks (dir) from a template dir?

2. If not, where is the function where it creates files under hooks dir and can it be modified?

3. Is it possible to create an extra hook and place it inside [Stash Install]/data/repositories/1/hooks/pre-receive.d or [Stash Install]/data/repositories/1/hooks/post-receive.d, when 'create repository' button is clicked?

Thanks,

Murtaza Pitalwala

2 answers

Comments for this post are closed

Community moderators have prevented the ability to post new answers.

Post a new question

0 votes
Murtaza Pitalwala December 19, 2013

Hello Charles,

I looked through the java plugins that may work for me and I found external-hooks and stash-reponame-plugin working together to be extremely helpful. I am finally able to achieve my goal, thanks to the two plugins I mentioned.

I found the following setup work for me. I am sharing this in case anyone else is looking for the same resolution.

My setup now includes:

1. Download and installing of the plugins: external-hooks and stash-reponame-plugin.

2. Creating a pre-receive and post-receive script.

3. Configuring external-hooks (both pre and post plugins) to point to the pre and post receive hooks created.

4. Enable the plugins as needed per repository.

and That's it!!!

Also, thank you for answering questions.

Oh and rate-limiting thing keeps happening.

cofarrell
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.
December 21, 2013

Hi Murtaza,

Glad to hear it's all working. I've send an email to someone about the rate-limiting.

Charles

Dennis Kromhout van der Meer
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.
December 22, 2013

Hi Murtaza,

I fixed the rate-limiting issue, please let me know if you run into trouble :)

Cheers,
Dennis

srikrishnap June 14, 2014

Hi Dennis ....I am a newbie to Stash . I need a way to create repository with validation of repository name using Stash SDK. What are the high level steps.?

Your help is highly appreciated.

0 votes
cofarrell
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.
December 17, 2013

Hi Murtaza,

The repositories structure is created by 'git init', which will use the globally configured git templates directory. This has nothing to do with Stash. If you add your own pre-receive.d and post-receive.d script to that template directory it should be copied into each new repository that is created. I also recommend to people to use symlinks.

https://answers.atlassian.com/questions/201605/stash-licenses-hooks/203060

Otherwise you can certainly write your own Java plugin that does this manually too if you prefer.

Cheers,

Charles

Murtaza Pitalwala December 17, 2013

Hello Charles,

Thanks for responding to this question.

Are you saying if I add my custom pre-receive and post-receieve scripts in /usr/share/git-core/templates/hooks/*, when a new repository is created by Stash "by clicking on the 'create repository' button", it will copy the custom scripts from /usr/share/git-core/templates/hooks/* to [Stash Install]/data/repositories/1/hooks/[pre|post]-receive.d/* or it will copy the files inside [Stash Install]/data/repositories/1/hooks/* ?

How can I make sure that it copies the files inside the [Stash Install]/data/repositories/1/hooks/pre-receive.d/* and [Stash Install]/data/repositories/1/hooks/post-receive.d/* directory? I am guessing by creating [pre|post]-receive.d/* directories and files inside /usr/share/git-core/templates/hooks/*?

I am asking this because I thought if the scripts are not inside [Stash Install]/data/repositories/1/hooks/[post|pre]-receive.d directory, it will be ignored.

If I were to create a custom java plugin that works with pre/post commits, how would I go about that?

Is it possible to show that custom created java plugin in Add Hook page and have it enable or disable per repository? For example the ones like "Reject Force Push" and "Stash Webhook to Jenkins" and so on and so forth.

Thanks,

Murtaza Pitalwala

cofarrell
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.
December 17, 2013

Hi Martaza,

That's correct - Git should copy _anything_ from the global templates directory into each new repository automatically. So creating pre-receive.d and post-receive.d directories with your hooks (that should be symlinks) will also be copied, and Stash will then add its own extra hooks. Once the repository has been created Git/Stash will _only_ look at the repository hooks, so you would have to manually copy/symlink your hooks into existing repositories.

If you want to create your own Java plugin/hook then the best place to start is our developer documentation:

https://developer.atlassian.com/stash/docs/latest/how-tos/repository-hooks.html

For your plugin it to appear on the hook page it needs to have a repository-hook module. Let me know if you have any more questions.

Cheers,

Charles

Murtaza Pitalwala December 18, 2013

Hello Charles,

Great Thanks. I have one more question.

How can I get the remote url from git or stash inside [pre|post]-receive script?

For example, I have a hook script under [Stash Install]/data/repositories/1/hooks/pre-receive.d/* and the link to the repo url is http://user@host:7990/scm/t/test1.git.

Now, how do I get this url in the [pre|post]-receive scripts? The git command to get the remote url is 'git config --get remote.origin.url' but it does not seem to work inside a [pre|post]-receive script. Is there another way to get the url?

Also, for some reason, I am not able to comment back for 24 hours because it says:

===================================================

You are currently rate-limited

Since you have posted 1 question, answer, or comment in the past 24 hours, you will not be able to post an answer until you have earned at least 1 karma

===================================================

If I dont reply back sooner, I really appreciate all the help from you.

Thanks,

Murtaza Pitalwala

cofarrell
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.
December 18, 2013

Hi Murtaza,

By default there isn't any way (one of the many reasons the Java plugins are better). You will have to install the following plugin:

https://bitbucket.org/atlassian/stash-reponame-plugin/downloads

You will then be able to run:

git config --get stash.project

git config --get stash.repository

We are planning on putting this on Marketplace very shortly.

I'm not sure what's happening with the rate-limiting I'm afraid. Let me know if it keeps happening.

Cheers,

Charles

TAGS
AUG Leaders

Atlassian Community Events