-
Notifications
You must be signed in to change notification settings - Fork 1.2k
/
check_integrity.sh
executable file
·95 lines (73 loc) · 2.46 KB
/
check_integrity.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
#!/usr/bin/env bash
err() {
echo >&2 "$1"
exit 1
}
make_doc() {
echo "touch man/git-$1.md && make man/git-$1.{1,html}"
}
check_bash_script() {
local cmd="git-$1"
test -f "bin/$cmd" \
|| err "bin/$cmd does not exist"
test -x "bin/$cmd" \
|| err "Run 'chmod +x bin/$cmd' to make it executable"
shebang=$(head -n1 "bin/$cmd")
[[ "$shebang" =~ \#![[:space:]]*/usr/bin/env[[:space:]]+bash ]] \
|| err "Start git-$1 with '#!/usr/bin/env bash'"
}
check_git_extras_cmd_list() {
local whitelist=('extras')
for cmd in "${whitelist[@]}"; do
test "$1" == "$cmd" && return
done
grep "\- \*\*git\-$1(1)\*\*" man/git-extras.md >/dev/null \
|| err "Add git-$1 in the list of commands in man/git-extras.md via $(make_doc "$1")"
}
check_man_page_index() {
grep "git\-$1(1) git\-$1" man/index.txt >/dev/null \
|| err "Add git-$1 to index.txt via $(make_doc "$1")"
}
check_documentation() {
local cmd="git-$1"
test -f "man/$cmd.md" || err "man/$cmd.md is required for bin/$cmd"
if [ ! -f "man/$cmd.1" ] || [ ! -f "man/$cmd.html" ]
then
err "Create man/$cmd.1 and man/$cmd.html via $(make_doc "$1")"
fi
if [ "man/$cmd.md" -nt "man/$cmd.1" ] || [ "man/$cmd.md" -nt "man/$cmd.html" ]
then
err "man/$cmd.md, man/$cmd.1, and man/$cmd.html all exist, but man/$cmd.md is newer. You should rm man/$cmd.{1,html} && $(make_doc "$1")"
fi
check_git_extras_cmd_list "$@"
check_man_page_index "$@"
}
check_Commands_page() {
# These are special cases. All listed together, so we ignore them
local whitelist=('bug' 'chore' 'feature' 'refactor')
for cmd in "${whitelist[@]}"; do
test "$1" == "$cmd" && return
done
grep "\- \[\`git $1\`\](#git-$1)" Commands.md >/dev/null \
|| err "Add git-$1 in the list of commands in Commands.md"
grep "^## git $1" Commands.md >/dev/null \
|| err "Add description of git-$1 in Commands.md"
}
check_completion() {
grep "$1:" etc/git-extras-completion.zsh > /dev/null || \
err "Add git-$1 to the completion list at the end of etc/git-extras-completion.zsh"
}
check() {
check_bash_script "$1"
check_documentation "$1"
check_Commands_page "$1"
check_completion "$1"
}
test $# == 0 && set -- $(find bin | cut -b 5- | xargs)
./bin/git-utimes --newer
for name in "$@"; do
name=${name#git-}
[[ "$name" == "rscp" ]] && continue
check "$name"
done
echo 'All done'