1010set -e
1111# constants
1212
13- GITHOOK_VERSION=" 0.1.9 "
13+ GITHOOK_VERSION=" 0.1.12 "
1414GITHOOK_API_URL=" https://githook.sh"
1515GITHOOK_DIR=" .githook"
1616GITHOOK_INTERNAL_DIR=" .githook/_"
@@ -127,6 +127,7 @@ githook_cmd_install() {
127127 # create shared hook runner
128128 cat > " $_git_root /$GITHOOK_INTERNAL_DIR /h" << 'HOOK '
129129#!/bin/sh
130+ [ -f "$HOME/.config/githook/init.sh" ] && . "$HOME/.config/githook/init.sh"
130131[ "$GITHOOK" = "2" ] && set -x
131132[ "$GITHOOK" = "0" ] && exit 0
132133n=$(basename "$0")
@@ -135,7 +136,7 @@ h=$(dirname "$(dirname "$0")")/$n
135136sh -e "$h" "$@"
136137c=$?
137138[ $c != 0 ] && echo "githook - $n failed (code $c)"
138- [ $c = 127 ] && echo "githook - command not found in PATH=$PATH "
139+ [ $c = 127 ] && echo "githook - command not found"
139140exit $c
140141HOOK
141142
@@ -176,10 +177,17 @@ githook_cmd_update() {
176177 _git_root=" $( githook_check_git_repository) "
177178 _path=" $_git_root /.githook.sh"
178179 [ ! -f " $_path " ] && githook_error " .githook.sh not found in repo root"
179- githook_info " updating .githook.sh..."
180- githook_download_file " $GITHOOK_API_URL " " $_path " || githook_error " failed to download update"
180+ githook_info " checking for updates..."
181+ _remote=" $( githook_download_file " $GITHOOK_API_URL " - 2> /dev/null) " || githook_error " failed to fetch latest version"
182+ _latest=" $( echo " $_remote " | grep ' ^GITHOOK_VERSION=' | cut -d' "' -f2) "
183+ case " $_latest " in [0-9]* .[0-9]* .[0-9]* ) ;; * ) githook_error " invalid remote version: $_latest " ;; esac
184+ githook_version_compare " $GITHOOK_VERSION " " $_latest "
185+ case $? in 0|1) githook_info " already up to date ($GITHOOK_VERSION )" ; return ;; esac
186+ githook_info " updating $GITHOOK_VERSION -> $_latest ..."
187+ echo " $_remote " > " $_path "
181188 chmod +x " $_path "
182- githook_info " updated successfully"
189+ githook_info " updated to $_latest "
190+ githook_info " run ./.githook.sh install to update hooks"
183191}
184192
185193githook_cmd_version () {
0 commit comments