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

Andy Zhou August 3, 2015

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

4 votes
Mark McCormack _Adaptavist_
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.
August 3, 2015

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
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.
August 3, 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);
    }
}
0 votes
Andy Zhou December 7, 2016

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
TAGS
AUG Leaders

Atlassian Community Events