下面是我在VS 2019中用于预提交的钩子代码。我想限制一些文件总是被提交。尝试使用string.exe。但是得到错误。需要帮助。
#!/bin/sh
#!/usr/bin/env bash
listchange=$(git diff --name-only)
echo "Check filenames:"
wrongfilenames=$(
for filename in $listchange
do
fname= $filename
if [[ $fname = 'strings.exe' ]]; then
echo $fname;
echo "has strings.exe"
fi
done
);
if [ -n "$wrongfilenames" ] ; then
echo "The following files need not to commit:"
echo "$wrongfilenames"
echo "Commit rejected, fix it and try again."
exit 1
else
echo "....OK"
1条答案
按热度按时间zqry0prt1#
在条件检查的末尾似乎缺少
fi
。注意:在检查字符串内容时,最好在$var前后加上双引号。实际上,如果$var有空格,它将无法正常工作。