4
0

pre-commit.py 634 B

12345678910111213141516171819202122
  1. #!/usr/bin/env python3
  2. import os,sys
  3. import subprocess
  4. def gitleaksEnabled():
  5. out = subprocess.getoutput("git config --bool hooks.gitleaks")
  6. if out == "false":
  7. return False
  8. return True
  9. if gitleaksEnabled():
  10. exitCode = os.WEXITSTATUS(os.system('gitleaks protect -v --staged'))
  11. if exitCode == 1:
  12. print('''Warning: gitleaks has detected sensitive information in your changes.
  13. To disable the gitleaks precommit hook run the following command:
  14. git config hooks.gitleaks false
  15. ''')
  16. sys.exit(1)
  17. else:
  18. print('gitleaks precommit disabled (enable with `git config hooks.gitleaks true`)')