From f60f127d577fcb82270da917c771eb4cc67234a7 Mon Sep 17 00:00:00 2001 From: spacewander Date: Mon, 25 Jul 2016 23:02:32 +0800 Subject: [PATCH 1/2] Add check integrity script --- check_integrity.sh | 50 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 50 insertions(+) create mode 100755 check_integrity.sh diff --git a/check_integrity.sh b/check_integrity.sh new file mode 100755 index 0000000..982c073 --- /dev/null +++ b/check_integrity.sh @@ -0,0 +1,50 @@ +#!/usr/bin/env bash + +err() { + echo "$1" + exit 1 +} + +check_bash_script() { + local cmd="git-$1" + test -x "bin/$cmd" || err "bin/$cmd is either non-existent or unexecutable" + shebang=$(head -n 1 "bin/$cmd") + test "$shebang" == "#!/usr/bin/env bash" || \ + err "start git-$1 with '#!/usr/bin/env bash'" +} + +check_documentation() { + local cmd="git-$1" + test -f "man/$cmd.md" || err "man/$cmd.md required" + test -f "man/$cmd.1" || err "man/$cmd.1 required" + test -f "man/$cmd.html" || err "man/$cmd.html required" +} + +check_Commands_page() { + 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 && \ + grep "^## git $1" Commands.md > /dev/null || \ + err "Update Commands.md with git-$1 is required" +} + +check_completion() { + grep "$1:" etc/git-extras-completion.zsh > /dev/null || \ + err "Update git-extras-completion.zsh with git-$1 is required" +} + +check() { + check_bash_script "$1" + check_documentation "$1" + check_Commands_page "$1" + check_completion "$1" +} + +test $# == 0 && err "Please give your command name" +for name in "$@"; do + [[ "$name" == "rscp" || "$name" == "line-summary" ]] && continue + check "$name" +done +echo 'All is done' From 53840911830e3872f485dcec8c32cf5b781e21cc Mon Sep 17 00:00:00 2001 From: spacewander Date: Fri, 29 Jul 2016 11:26:03 +0800 Subject: [PATCH 2/2] update check_integrity with nicolaiskogheim's patch --- check_integrity.sh | 53 +++++++++++++++++++++++++++++++++------------- 1 file changed, 38 insertions(+), 15 deletions(-) diff --git a/check_integrity.sh b/check_integrity.sh index 982c073..cc029a4 100755 --- a/check_integrity.sh +++ b/check_integrity.sh @@ -1,38 +1,51 @@ #!/usr/bin/env bash err() { - echo "$1" + echo >&2 "$1" exit 1 } check_bash_script() { local cmd="git-$1" - test -x "bin/$cmd" || err "bin/$cmd is either non-existent or unexecutable" - shebang=$(head -n 1 "bin/$cmd") - test "$shebang" == "#!/usr/bin/env bash" || \ - err "start git-$1 with '#!/usr/bin/env bash'" + + 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") + test "$shebang" == "#!/usr/bin/env bash" \ + || err "Start git-$1 with '#!/usr/bin/env bash'" } check_documentation() { local cmd="git-$1" - test -f "man/$cmd.md" || err "man/$cmd.md required" - test -f "man/$cmd.1" || err "man/$cmd.1 required" - test -f "man/$cmd.html" || err "man/$cmd.html required" + test -f "man/$cmd.md" || err "create man/$cmd.md" + + if [ ! -f "man/$cmd.1" ] || [ ! -f "man/$cmd.html" ] + then + err "Run 'make docs' to create man/$cmd.1 and man/$cmd.html" + fi } 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 && \ - grep "^## git $1" Commands.md > /dev/null || \ - err "Update Commands.md with git-$1 is required" + + 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 "Update git-extras-completion.zsh with git-$1 is required" + err "Add git-$1 to the completion list at the end of etc/git-extras-completion.zsh" } check() { @@ -42,9 +55,19 @@ check() { check_completion "$1" } -test $# == 0 && err "Please give your command name" +usage() { + echo >&2 "Usage: ./check_integrity.sh [ ...]" + exit 0 +} + +test $# == 0 && usage + for name in "$@"; do - [[ "$name" == "rscp" || "$name" == "line-summary" ]] && continue + name=${name#git-} + [[ "$name" == "rscp" || "$name" == "line-summary" ]] && echo "Skip command $name" \ + && continue check "$name" done -echo 'All is done' + +echo 'All done' +exit 0