此预提交的挂钩将执行文件大小检查:
.git / hooks / pre-commit
#!/bin/shhard_limit=$(git config hooks.filesizehardlimit)soft_limit=$(git config hooks.filesizesoftlimit): ${hard_limit:=10000000}: ${soft_limit:=500000}list_new_or_modified_files(){ git diff --staged --name-status|sed -e '/^D/ d; /^D/! s/.s+//'}unmunge(){ local result="${1#"}" result="${result%"}" env echo -e "$result"}check_file_size(){ n=0 while read -r munged_filename do f="$(unmunge "$munged_filename")" h=$(git ls-files -s "$f"|cut -d' ' -f 2) s=$(git cat-file -s "$h") if [ "$s" -gt $hard_limit ] then env echo -E 1>&2 "ERROR: hard size limit ($hard_limit) exceeded: $munged_filename ($s)" n=$((n+1)) elif [ "$s" -gt $soft_limit ] then env echo -E 1>&2 "WARNING: soft size limit ($soft_limit) exceeded: $munged_filename ($s)" fi done [ $n -eq 0 ]}list_new_or_modified_files | check_file_size
上面的脚本必须另存为
.git/hooks/pre-commit启用执行权限(
chmod +x .git/hooks/pre-commit)。
默认的软(警告)和硬(错误)大小限制设置为500,000和10,000,000字节,但可以分别通过
hooks.filesizesoftlimit和
hooks.filesizehardlimit设置覆盖它们:
$ git config hooks.filesizesoftlimit 100000$ git config hooks.filesizehardlimit 4000000
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)