pre-commit.sh 653 B

12345678910111213141516171819202122232425262728293031
  1. #!/bin/sh
  2. #
  3. # To enable this hook, issue:
  4. #
  5. # ln -s scripts/pre-commit.sh .git/hooks/pre-commit
  6. #
  7. RED='\033[0;31m'
  8. NC='\033[0m'
  9. ## Throw error if any files contain "std::__1"
  10. # list of changed files
  11. CHANGED=$(git diff --cached --name-only --diff-filter=ACM)
  12. # Changed files containing the namespace "std::__1"
  13. STD1=$(grep -Il "std::__1" $CHANGED)
  14. if [ $? -eq 0 ]; then
  15. STD1=$(echo "$STD1" | sed -e "s/^/ /")
  16. >&2 echo "[pre-commit hook] Error: Commit prohibited.
  17. The following files contain the offensive \"std::__1\" namespace:
  18. ${RED}$STD1${NC}
  19. Consider issueing:
  20. sed -i '' -e \"s/std::__1/std/g\"" $STD1
  21. exit 1
  22. else
  23. exit 0
  24. fi