Loading git-hooks +32 −7 Original line number Diff line number Diff line Loading @@ -36,6 +36,7 @@ HOOKS="update pre-receive post-receive" usage () { local IFS for func in `declare -F | cut -f3 -d\ | grep ^cmd_`; do commands=( "${commands[@]}" ${func#cmd_} ) done Loading Loading @@ -66,6 +67,11 @@ mv_unique () rm "$src" } path () { echo "$GIT_DIR/hooks/${1:+$1.d}${2+/$2}" } cmd_init () { summary="set up git-hook directories in a repository" Loading Loading @@ -99,6 +105,7 @@ cmd_init () [ x$ignore_def == xyes ] && continue unset IFS defaults=`$GIT_CONFIG --get git-hooks.$hook` || continue IFS=$',' defaults=( $defaults ) for default in "${defaults[@]}"; do Loading Loading @@ -129,9 +136,10 @@ _change_check () _installed_check () { [ -e "$GIT_DIR"/hooks/$hook.d/"$script" ] && \ ! [ -d "$GIT_DIR"/hooks/$hook.d/"$script" ] || \ local path=`path $hook "$script"` if ! ( [ -e "$path" ] && ! [ -L "$path" ] ) && [ -d "$path" ]; then die "there is no script '$script' in the '$hook' hook directory" fi } cmd_add () Loading Loading @@ -177,6 +185,7 @@ cmd_enable () { summary="enable a script from a hook" local hook script local path link add_option hook yes add_option script yes parse_args "$@" || return Loading @@ -184,13 +193,22 @@ cmd_enable () _change_check "$@" _installed_check "$@" path=`path $hook "$script"` if [ -L "$path" ]; then link=`readlink "$path"` link="${link#disabled:}" rm "$path" ln -s "$link" "$path" else chmod +x "$GIT_DIR"/hooks/$hook.d/"$script" fi } cmd_disable () { summary="disable a script from a hook" local hook script local path link add_option hook yes add_option script yes parse_args "$@" || return Loading @@ -198,7 +216,14 @@ cmd_disable () _change_check "$@" _installed_check "$@" path=`path $hook "$script"` if [ -L "$path" ]; then link=`readlink "$path"` rm "$path" ln -s "disabled:$link" "$path" else chmod -x "$GIT_DIR"/hooks/$hook.d/"$script" fi } cmd_installed () Loading @@ -209,8 +234,8 @@ cmd_installed () parse_args "$@" || return _basic_check "$@" cd "$GIT_DIR"/hooks/$hook.d find -type f -printf '%P\n' cd "`path $hook`" find -type f -o -type l -printf '%P\n' } cmd_hooks () Loading Loading
git-hooks +32 −7 Original line number Diff line number Diff line Loading @@ -36,6 +36,7 @@ HOOKS="update pre-receive post-receive" usage () { local IFS for func in `declare -F | cut -f3 -d\ | grep ^cmd_`; do commands=( "${commands[@]}" ${func#cmd_} ) done Loading Loading @@ -66,6 +67,11 @@ mv_unique () rm "$src" } path () { echo "$GIT_DIR/hooks/${1:+$1.d}${2+/$2}" } cmd_init () { summary="set up git-hook directories in a repository" Loading Loading @@ -99,6 +105,7 @@ cmd_init () [ x$ignore_def == xyes ] && continue unset IFS defaults=`$GIT_CONFIG --get git-hooks.$hook` || continue IFS=$',' defaults=( $defaults ) for default in "${defaults[@]}"; do Loading Loading @@ -129,9 +136,10 @@ _change_check () _installed_check () { [ -e "$GIT_DIR"/hooks/$hook.d/"$script" ] && \ ! [ -d "$GIT_DIR"/hooks/$hook.d/"$script" ] || \ local path=`path $hook "$script"` if ! ( [ -e "$path" ] && ! [ -L "$path" ] ) && [ -d "$path" ]; then die "there is no script '$script' in the '$hook' hook directory" fi } cmd_add () Loading Loading @@ -177,6 +185,7 @@ cmd_enable () { summary="enable a script from a hook" local hook script local path link add_option hook yes add_option script yes parse_args "$@" || return Loading @@ -184,13 +193,22 @@ cmd_enable () _change_check "$@" _installed_check "$@" path=`path $hook "$script"` if [ -L "$path" ]; then link=`readlink "$path"` link="${link#disabled:}" rm "$path" ln -s "$link" "$path" else chmod +x "$GIT_DIR"/hooks/$hook.d/"$script" fi } cmd_disable () { summary="disable a script from a hook" local hook script local path link add_option hook yes add_option script yes parse_args "$@" || return Loading @@ -198,7 +216,14 @@ cmd_disable () _change_check "$@" _installed_check "$@" path=`path $hook "$script"` if [ -L "$path" ]; then link=`readlink "$path"` rm "$path" ln -s "disabled:$link" "$path" else chmod -x "$GIT_DIR"/hooks/$hook.d/"$script" fi } cmd_installed () Loading @@ -209,8 +234,8 @@ cmd_installed () parse_args "$@" || return _basic_check "$@" cd "$GIT_DIR"/hooks/$hook.d find -type f -printf '%P\n' cd "`path $hook`" find -type f -o -type l -printf '%P\n' } cmd_hooks () Loading