I'm using Bitbucket Server 6.6.2 with the latest Script Runner for Bitbucket Server.
We had an issue with new users using a mis-configured (or not configured) git-lfs. It was not tracking the right file types and the users were accidentally submitting these large files (PDFs) directly to the repo, then things went haywire between some correctly configured clients and the not-correctly configured clients.
After cleaning everything up, we wanted to add a safeguard to keep these large PDF files from being submitted again. Since git-lfs replaces the real file contents with pointers to the git-lfs file store, the actual size of the PDF files committed to our main git repo are not that big. Looking at the size of the pointer files, it looks like 200B is plenty large enough to allow the pointers through, but plenty small enough to disallow any real PDFs.
Before we upgraded to Bitbucket Server 6+, we were using a plugin that did this perfectly. Unfortunately, this plugin is no longer under development, so we needed to find something else to do this job. Enter Script Runner for Bitbucket Server, which we were already using for another task. The "restrict file size" pre-commit hook seemed to fit the bill nicely. We told it to looks for PDFs (with `pathsMatch('glob:**.pdf')`) and gave it a max size of 200B.
This works well if the commit consists of only PDFs. The problem is that if there's a mix of files in the commit, then the file size limit applies to all files in the commit, not just the ones matched with 'pathsMatch()`. For example, a commit is rejected if someone checks in a 132B PDF and a 1K MD file. Right now, I have the users of this repo only committing PDFs by themselves and not with any other file types, but I'd like to have them not be concerned about this.
The fixes I can think of are:
1. Update the condition in the restrict file size pre-commit hook somehow.
2. Write a custom script hook.
3. Not use SR for BS and write a shell script.
Options 1 and 2 are kind of iffy because I've never used Groovy before and I'm not exactly sure what information is being passed to the plugin. On the other hand, it's just another programming language, so it shouldn't be too hard, if I can figure what goes where and what's exposed to the script. It seems that SR is so close to what I'm looking for that it shouldn't be too difficult to do, yet I'm hitting walls with everything I attempt.
Option 3 is appealing because I'm a shell scripter at heart ("When all you have is a hammer..."), but I'd rather not do hooks 50 different ways, so if I can keep everything contained within SR, all the better.
Anyone have advice for how to address this issue?
Thanks,
Pete