0

I'd need to create a pre-receive hook for Stash (Atlassian) that can validate the file types in each commit. The goal is to reject types that are supposed to be stored in Maven, e.g.: DLL files, images, etc.

I found some examples for hooks, but I can't really understand any of them (unfamiliar with this Linux-friendly side of IT). Could anybody help me out with how to start?

How to create a Hook script that has access to the file types/names in a commit?

Marcus Müller
  • 34,677
  • 4
  • 53
  • 94
Tyrel
  • 81
  • 5
  • The thing to do is to pick an language which you know (and have installed on the target machine) to write your hooks in. The first example you linked to is a ruby script. The only part that is Linux-related is the first line (called a she-bang), which gives the command to be executed. You could pass in arguments to `ruby`, e.g. `#!/usr/bin/env ruby -w` – jpaugh Feb 01 '16 at 14:56
  • So, any programming system which can be told to execute a script from the command line will work here. `#!/usr/bin/python` (or `#!/usr/bin/env python`) would work just as well. (This works as long as that language can be convinced to ignore the first line, which Python, bash, or ruby does.) – jpaugh Feb 01 '16 at 14:58
  • Which ones are supported natively? I'm fine with ruby, python, or pretty much anything else. I just need a starting point, like: "here, put this script in the X directory of your Stash server, it will run whenever users push something, and you will have list of committed files in the Y variable" or something like that. No need for a full solution, I just really don't know how to start out. – Tyrel Feb 01 '16 at 15:02
  • You can update files type in gitignore file. – binarymemoir Feb 01 '16 at 15:04
  • Yeah we tried gitignore, doesn't really work. Devs just surpass it or force-add files, because they hate using Maven. :P The goal is to make the server not allow people to commit the unwanted files, whatever they do. – Tyrel Feb 01 '16 at 15:06
  • @Tyrel I know nothing about *Stash*, so I can't say. Python and Ruby are both well supported though; and, you could expect to find Bash and Perl on almost any modern Unix server. – jpaugh Feb 01 '16 at 16:22

0 Answers0