So I am using pre-receive hook in GitHub Enterprise to find confidential information in commits made by user when he tries to push code. I am following this script for this purpose. This works fine one user commits confidential information for the first time. But even when user remove confidential information, this script still returns that in difference hence an infinite loop. Any help regarding this will be great as I am not able to figure out how to fix this problem.
Step by Step:
- clone repository on local drive
- make multiple commits
- add confidential information in between
- now try to push
- script will return commit with PIIs and rightly so
- now remove PIIs from files and commit
- push and I'll get difference from all previous commits
Problem is, I want only latest updated difference excluding changes overwritten. I can achieve this on local branch by running following command:
git diff origin/main | grep -Po '(?<=^\+)(?!\+\+).*'
But I can't run above command in shell script as I get "no workfree available" error. I think all we need is to update following command in line # 64 in attached script.
Thanks