@@ -7,6 +7,7 @@ readonly GIT_TOPDIR=$(git rev-parse --show-toplevel 2>/dev/null || :)
77[[ -z ${NR_MOD} ]] && NR_MOD=4
88[[ -z ${NR_ADD} ]] && NR_ADD=1
99[[ -z ${NR_DEL} ]] && NR_DEL=1
10+ [[ -z ${FORCE} ]] && FORCE=
1011
1112if [[ ${V} ]] || [[ ${VERBOSE} ]]; then
1213 set -x
@@ -16,21 +17,24 @@ try_add=( $(git status --short | grep ^A | awk '{print $2}' || true) )
1617try_del=( $( git status --short | grep ^D | awk ' {print $2}' || true) )
1718try_modify=( $( git status --short | grep ^M | awk ' {print $2}' || true) )
1819
20+ fatal () {
21+ echo >&2 " FATAL: " ${@ }
22+ exit 1
23+ }
24+
1925# Redirect output to stderr.
2026exec 1>&2
2127
22- must_modify_changelog () {
23- if ! [[ " ${try_modify[@]} " =~ CHANGELOG.md ]]; then
28+ hint_changelog () {
29+ if ! [[ " ${try_modify[@]} " =~ " CHANGELOG.md " ]]; then
2430 git status --short
25- echo " FATAL: you forgot modify CHANGELOG.md !!"
26- exit 1
31+ fatal " ${@ } " " you forgot modify CHANGELOG.md!!! Try FORCE???"
2732 fi
2833}
2934
3035broken_symlinks=( $( find ${GIT_TOPDIR} -xtype l) )
3136if [[ ${# broken_symlinks[@]} -ge 1 ]]; then
32- echo >&2 " Broken-symlink: ${broken_symlinks[@]} "
33- exit 1
37+ fatal " Broken-symlink: ${broken_symlinks[@]} "
3438fi
3539
3640for f in ${try_add[@]}
4044 # true: for empty file
4145 read -r -N 8 bin < $f || true
4246 if [[ $bin == $' \x7f ' ELF* ]]; then
43- echo " FATAL: You are trying to add <$f > ELF file to git-tree, see git status."
44- exit 1
47+ fatal " You are trying to add <$f > ELF file to git-tree, see git status."
4548 # ar file start from "!<arch>\n", see /usr/include/ar.h
4649 elif [[ $bin == $' !<arch>\n ' ]]; then
47- echo " FATAL: You are trying to add <$f > ar file to git-tree, see git status."
48- exit 1
50+ fatal " You are trying to add <$f > ar file to git-tree, see git status."
4951 elif [[ $bin == $' gmon' * ]]; then
50- echo " FATAL: You are trying to add <$f > GNU prof performance file to git-tree, see git status."
51- exit 1
52+ fatal " You are trying to add <$f > GNU prof performance file to git-tree, see git status."
5253 fi
5354 if [[ $( basename $f ) == vmlinux.h ]]; then
54- echo " FATAL: vmlinux.h is too big, generate it with bpftool command!!!"
55- exit 1
55+ fatal " vmlinux.h is too big, generate it with bpftool command!!!"
56+ fi
57+ if [[ $( file $f | awk ' {print $NF}' ) == data ]] && [[ -z ${FORCE} ]]; then
58+ fatal " $f is considered a data file!!! try FORCE"
5659 fi
5760done
5861
59- # modify too much files or delete files, need modify CHANGELOG.md too
60- if [[ ${# try_modify[@]} -ge ${NR_MOD} ]] || \
61- [[ ${# try_del[@]} -ge ${NR_DEL} ]] || \
62- [[ ${# try_add[@]} -ge ${NR_ADD} ]]; then
63- must_modify_changelog
64- fi
62+ # modify,add, delete files, need modify CHANGELOG.md too
63+ [[ ${# try_modify[@]} -ge ${NR_MOD} ]] && hint_changelog " <Modify too many files> "
64+ [[ ${# try_del[@]} -ge ${NR_DEL} ]] && hint_changelog " <Delete files> "
65+ [[ ${# try_add[@]} -ge ${NR_ADD} ]] && hint_changelog " <Add files: ${try_add[@]} > "
66+
67+ exit 0
0 commit comments