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