在预先提交git钩子中使用正则表达式的grep [英] grep with regex in pre-commit git hook
本文介绍了在预先提交git钩子中使用正则表达式的grep的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
FORBIDDEN => 'console.log'
但是当我更改为:
FORBIDDEN ='die(| console.log(| print_r('
它无法捕捉任何内容。
完整代码:
FILES_PATTERN ='(\ .. +)?$'
FORBIDDEN ='die(| console.log(| print_r('
git diff --cached - -name-only | \
grep -E $ FILES_PATTERN | \
xargs grep -E --with-filename -n $ FORBIDDEN | \
grep -v'//' ;
不知道它的正则表达式或其他东西
FORBIDDEN ='die \(| h2_lin>解决方案
尝试转义括号: console.log\(| print_r\('
I'm writing a little pre-commit hook to check for debug code this works well when using:
FORBIDDEN='console.log'
but when I change to:
FORBIDDEN='die(|console.log(|print_r('
it fails to catch anything.
FULL CODE:
FILES_PATTERN='(\..+)?$'
FORBIDDEN='die(|console.log(|print_r('
git diff --cached --name-only | \
grep -E $FILES_PATTERN | \
xargs grep -E --with-filename -n $FORBIDDEN | \
grep -v '//';
Not sure if its regex or something else
解决方案
Try escaping your parenthesis:
FORBIDDEN='die\(|console.log\(|print_r\('
这篇关于在预先提交git钩子中使用正则表达式的grep的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文