this repo has no description
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

Improve hook handler

+23 -11
+23 -11
git/hooks/hook.sh
··· 4 4 5 5 usage() { 6 6 echo "$0 [install|help]" 7 + echo 'Version 0.1.0' 8 + echo 'Copyright (c) Łukasz Niemier <opensource@niemier.pl>' 7 9 echo 8 - echo "Simple git hooks management system" 10 + echo 'Simple git hooks management system' 11 + echo 12 + echo 'install [hook_dir]' 13 + echo ' Installs hooks for given repo.' 14 + echo 15 + echo ' [hook_dir] - directory where install hooks, defaults to .git/hooks' 16 + echo ' in current Git working directory' 17 + echo 'help' 18 + echo ' display this message' 19 + echo 20 + echo 'To use this as default set of hooks when creating new repo then:' 21 + echo 22 + echo " 1. Run '$0 ~/.githooks'" 23 + echo ' 2. Run 'git config --global core.hooksPath ~/.githooks'' 9 24 echo 10 25 } 11 26 12 27 install() { 13 28 source="${BASH_SOURCE[0]}" 14 - DIR="${1:-"$(git rev-parse --show-toplevel)"}" 15 - HOOK_DIR="${2:-"$DIR/.git/hooks"}" 29 + HOOK_DIR="${1:-"$(git rev-parse --show-toplevel)/.git/hooks"}" 16 30 17 31 echo "Install handler" 18 32 echo ··· 34 48 script="$(basename "$0")" 35 49 PLUG_DIRS=("$(command git config --get hooks.path)" "$GIT_DIR/hooks/hooks.d") 36 50 37 - echo "## Hook $script" 38 - echo 39 - 40 51 test -d "$GIT_DIR"/rebase-merge -o -d "$GIT_DIR"/rebase-apply && exit 0 41 52 42 53 for dir in "${PLUG_DIRS[@]}" ··· 44 55 if [ -d "$dir" ] 45 56 then 46 57 find "$dir" -depth 2 -and -name "$script" -print0 2>/dev/null \ 47 - | xargs -t0 -n1 -I_ sh -c '[ -x "$1" ] && printf "\n###### %s\n" "$1" && "$@" && echo "ok"' -- _ "$@" 58 + | xargs -0 -n1 -I_ sh -c 'if [ -x "$1" ]; then printf "\n###### %s\n" "$1" && "$@" && echo "ok"; fi' -- _ "$@" 59 + retval="$?" 48 60 49 - if [ ! "$?" -eq 0 ] 61 + if [ ! "$retval" -eq 0 ] 50 62 then 51 - return "$?" 63 + return "$retval" 52 64 fi 53 65 fi 54 66 done ··· 58 70 install) 59 71 shift 60 72 install 61 - exit 0 73 + exit 62 74 ;; 63 - help) 75 + help|-h|--help|version|-v|-V|--version) 64 76 shift 65 77 usage 66 78 exit