A client side Git hook that I wrote and are using at work. Thought others might have a similar need. Basically it will check the selenium file for the owners and see if our group is in that ownership. If the file is not in our group a message is displayed saying that the owner will need to get permissions and code review by the owners.
Of course you can use any language you want to execute your client side git hook. I thought shell scripting would just be easiest in my case since it wasn’t going to be that much code and anyone that has git will either be running in windows with cygwin and thus of bash or they will be in Linux.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 | #!/bin/bash # # This hook is meant to do a pre-check to see if we have # files outside of common components that need dac # permissions # # Contact: Ryan Alberts # ############################################################# #Get the modified files files_modified=`git diff --cached --name-only` #echo "The present working directory is `pwd`" #false or 0 if we do not need dac permissions need_dac=0 #Commit message commit_msg=`cat $1` if [[ $commit_msg == *DAC* ]] then exit 0 fi #Go through the files in the submission for file in ${files_modified[@]} do accepted_path=0 check=`grep -s wc-caIntegSprintTester $file` #Check if it is apart of our package if [[ $check == *wc-caIntegSprintTester* ]] then accepted_path=1 fi if [ $accepted_path -eq 0 ] then echo "File is owned by another team, and may require DAC permissions!" echo " File: $file" need_dac=1 fi done #Exit Code For Commit Message Warning Or Not if [ "$need_dac" -eq "1" ] then echo "" echo ">>> Notice <<<" echo "Please contact the branch master and work on requesting DAC permissions for the files listed above." echo "You can avoid seeing this message by adding 'DAC' anywhere within the commit message." echo "" exit 1 fi #Everything looks good - allow them to commit. exit 0 |