下面是我在 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"
uj5u.com熱心網友回復:
看起來您fi在條件檢查結束時缺少 a 。
#!/bin/bash
listchange=$(git diff --name-only)
echo "Check filenames:"
wrongfilenames=$(
for filename in $listchange
do
if [[ "$filename" = "strings.exe" ]]; then
echo "$filename"
echo "has strings.exe"
# TODO: take the appropriate action(s) here
return 1 # => quit with error
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"
fi
注意:根據字串檢查內容時,最好在 $var 周圍添加雙引號。實際上,如果 $var 有空格,它將無法按預期作業。
轉載請註明出處,本文鏈接:https://www.uj5u.com/gongcheng/512831.html
標籤:壳预提交钩子
上一篇:linuxdate--以分鐘為單位增加當前日期,但防止溢位(超過午夜)
下一篇:使用帶有條件的AWK合并兩個檔案
