您可以使用
PowerShell任务
在PR validation build定义中,检查回购根目录中是否有文件,脚本如下:
$files=$(git ls-files)
echo $files
echo $files.length
for ($i=0; $i -lt $files.Length; $i++)
{
$file = $files[$i]
if ($file -match "/")
{ echo "the file $file in subdir" }
else
{
echo "the file $file in root dir"
exit 1
}
}
此外,您可以使用
预提交挂钩
在本地repo中,以便检测根目录中是否有要提交的文件
提交和推送之前
。该脚本可用于预提交挂钩,如下所示:
#!/bin/sh
for sfile in $(git diff --name-only --cached)
do
{
if [[ $sfile =~ "/" ]]; then
echo "the file $sfile in subdir"
else
echo "the file $sfile in root, stop to commit!"
exit 1
fi
}
done
for ufile in $(git diff --name-only)
do
{
if [[ $ufile =~ "/" ]]; then
echo "the file $ufile in subdir"
else
echo "the file $ufile in root, stop to commit!"
exit 1
fi
}
done