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

Andy,

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" ( https://marketplace.atlassian.com/plugins/com.wittified.stash.js-hooks ) to do it on a per repository basis. Something like:

function verifyFiles( files)
{
	for(var i=0;i<files.length;i++)
    {
    	if(files[i].path().endsWith('.doc'))
        {
        
        	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
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 ...

402 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