瀏覽代碼

pre commit hook

Former-commit-id: b9f24f092623aad13fdc45a951499811e814bdc1
Alec Jacobson 9 年之前
父節點
當前提交
2363e029e7
共有 1 個文件被更改,包括 31 次插入0 次删除
  1. 31 0
      scripts/pre-commit.sh

+ 31 - 0
scripts/pre-commit.sh

@@ -0,0 +1,31 @@
+#!/bin/sh
+#
+# To enable this hook, issue:
+#
+#     ln -s scripts/pre-commit.sh .git/hooks/pre-commit
+#
+RED='\033[0;31m'
+NC='\033[0m'
+
+## Throw error if any files contain "std::__1"
+
+# list of changed files
+CHANGED=$(git diff --cached --name-only --diff-filter=ACM)
+# Changed files containing the namespace "std::__1"
+STD1=$(grep -Il "std::__1" $CHANGED)
+if  [ $? -eq 0 ]; then
+  STD1=$(echo "$STD1" | sed -e "s/^/  /")
+  >&2 echo "[pre-commit hook] Error: Commit prohibited.
+
+The following files contain the offensive \"std::__1\" namespace: 
+
+${RED}$STD1${NC}
+
+Consider issueing:
+
+    sed -i '' -e \"s/std::__1/std/g\"" $STD1
+
+  exit 1
+else
+  exit 0
+fi