Can Stash prevent pushing certain file extensions to the remote server?

I'm new to Stash.  We like to set up the environment so people cannot add large binary files (such as MS Office files, PDF, JAR, etc.) to the Git repository.  Besides setting up global .gitignore files for each desktop and repository, it'd be nicer that Stash server could prevent push user repository with such files to the central Git repository.

Thanks and any help is greatly appreciated.


3 answers


Adaptavist have recently released an Add-on to the Atlassian Marketplace called ScriptRunner for Stash that can do exactly what you are looking for.

Our documentation outlines how you can restrict the file size for any file (including binaries) by configuring a Pre-receive hook to achieve it.

There is also a video on our Adaptavist ScriptRunner Youtube channel that will walk you through a number of Pre-receive hooks including the prevention of large files.

This screenshot shows you the Administration screen that would configure a restriction of 10MB to all files with the extension of .css and .js which you could extend to include MS Office files, PDFs and JAR files:

Screen Shot 2015-08-03 at 18.02.23.png 

I hope that helps

1 vote
Daniel Wester Community Champion Aug 03, 2015

Take a look at the Atlassian Marketplace to see if there are any pre-receive hooks that can help you. You can use ours "Javascript hooks for Stash" ( ) to do it on a per repository basis. Something like:

function verifyFiles( files)
	for(var i=0;i<files.length;i++)
        	stash.sendFeedback('Invalid file extension', files[i].path+' was in the commit. Please remove', true);
for(var c=0;c<changeSet.length;c++)
	var commits = stash.fetchCommits( project.key, repository.slug, changeSet[c].fromHash , changeSet[c].toHash);
    for(var commitCounter=0;commitCounter<commits.length;commitCounter++)
    	verifyFiles( commits[commitCounter].filesAdded);
    	verifyFiles( commits[commitCounter].filesModified);
    	verifyFiles( commits[commitCounter].filesMoved);
    	verifyFiles( commits[commitCounter].filesCopied);
    	verifyFiles( commits[commitCounter].filesUnknown);

Thank you both Mark the Daniel.  It's been a while, but we ended up doing it (along with few other things) with pre-receive hook.

Suggest an answer

Log in or Sign up to answer
How to earn badges on the Atlassian Community

How to earn badges on the Atlassian Community

Badges are a great way to show off community activity, whether you’re a newbie or a Champion.

Learn more
Community showcase
Posted Jun 12, 2018 in Bitbucket

Do you use any Atlassian products for your personal projects?

After spinning my wheels trying to get organized enough to write a book for National Novel Writing Month (NaNoWriMo) I took my affinity for Atlassian products from my work life and decided to tr...

21,857 views 26 11
Join discussion

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