pre-commit.sh 740 B

123456789101112131415161718192021222324252627282930313233
  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. # Ignore this file!
  13. CHANGED=$(echo "$CHANGED" | grep -v "scripts/pre-commit.sh")
  14. # Changed files containing the namespace "std::__1"
  15. STD1=$(grep -Il "std::__1" $CHANGED)
  16. if [ $? -eq 0 ]; then
  17. STD1=$(echo "$STD1" | sed -e "s/^/ /")
  18. >&2 echo "[pre-commit hook] Error: Commit prohibited.
  19. The following files contain the offensive \"std::__1\" namespace:
  20. ${RED}$STD1${NC}
  21. Consider issueing:
  22. sed -i '' -e \"s/std::__1/std/g\"" $STD1
  23. exit 1
  24. else
  25. exit 0
  26. fi