bash - 访问 git pre-receive 钩子中的更改文件并搜索字符串模式
问题描述
我有一个预提交脚本/钩子可以很好地搜索文件中的特定字符串模式并拒绝提交。我不确定如何读取预接收脚本中的传入文件以搜索字符串模式。
我的预提交脚本如下所示:
#!/usr/bin/env bash
if git rev-parse --verify HEAD >/dev/null 2>&1
then
against=HEAD
else
# Initial commit: diff against an empty tree object
EMPTY_TREE=$(git hash-object -t tree /dev/null)
against=$EMPTY_TREE
fi
FILES=$(git diff --cached --name-only $against)
if [ -n "$FILES" ]; then
string1 = $(grep -rE --line-number 'access_key' $FILES)
if [ -n "$string1" ] then
echo "string1 there so reject it"
while true; do
exit 1;
done
fi
fi
我不确定如何将其转换为 git 服务器端的预接收挂钩脚本。我已经尝试了几个小时没有运气。有人可以帮我吗?
解决方案
推荐阅读
- python - 无法解码 SQL 数据库,遵循烧瓶教程
- grails - Grails 数据库迁移插件,Grails 4
- c# - C# & SQL Server:在打开数据读取器时执行另一个查询
- reactjs - 如何使用 swr 编写测试
- xml - 使用 xslt 从 xml 文件中删除基于条件的重复记录
- arrays - SHA - 为什么用 0x80 和 0x01 填充?
- c# - 在 Windows 窗体中添加到 Git 存储库的文件
- python - TypeError:只有整数标量数组可以转换为标量索引,请大家帮我看看有什么问题吗?
- laravel - laravel 验证问题 - 验证不起作用
- python - 我正在为 7 段显示编写代码(不是 arduino 代码)我想在单行上打印输出