1

I have a requirement to search all incoming committed files, grep for string and decide, whether to allow or deny commits.

Below is my script which is doing great for a single commit, but if I commit the same file twice - it is not getting the first committed file/data, it is only getting the final commit. Could someone, please, help me to get script working for all the commits?

#!/usr/bin/env bash

while read oldrev newrev refname; do
    files=`git diff --name-only ${oldrev} ${newrev}`
    for file in ${files}; do
      git show $newrev:$file | grep -i "network-cidr"  
      result=$?
      if [ "$result" -eq "0" ]
      then
        echo "Found network cidr word so .. Denying the push"
        exit 1;
      fi  
    done;
done 

exit 0
larsks
  • 277,717
  • 41
  • 399
  • 399
latech
  • 73
  • 1
  • 10
  • Hello team, Seems thats in perl not sure how to covert that into my bash..can you please help me. – latech Nov 02 '18 at 23:15

0 Answers0