From 33f47cd3134f21731f19e1260ed8c5ef36ee04d2 Mon Sep 17 00:00:00 2001 From: Zearin Date: Mon, 28 Apr 2014 14:40:49 -0400 Subject: Put related functions next to each other --- git-hooks | 58 +++++++++++++++++++++++++++++----------------------------- 1 file changed, 29 insertions(+), 29 deletions(-) diff --git a/git-hooks b/git-hooks index 8ec9f13..aa55f72 100755 --- a/git-hooks +++ b/git-hooks @@ -57,6 +57,30 @@ function list_hooks_in_dir fi } +function list_hooks +{ + GITDIR=`git rev-parse --git-dir` + cat "${GITDIR}/hooks/pre-commit" 2> /dev/null | grep 'git-hooks' > /dev/null 2> /dev/null + if [ $? = 0 ] ; then + echo "Git hooks ARE installed in this repository." + echo "" + else + echo "Git hooks are NOT installed in this repository. (Run 'git hooks --install' to install it)" + echo "" + fi + + echo 'Listing User, Project, and Global hooks:' + echo '---' + for dir in `hook_dirs`; do + echo "${dir}:" + for hook in `list_hooks_in_dir "${dir}" 2` ; do + echo -n `basename \`dirname "${hook}"\`` + echo -e "/`basename "${hook}"` \t- `${hook} --about`" + done + echo "" + done +} + function run_hooks { dir="${1}" @@ -138,35 +162,6 @@ git-hooks run "$0" "$@"'; fi } -function list_hooks -{ - GITDIR=`git rev-parse --git-dir` - cat "${GITDIR}/hooks/pre-commit" 2> /dev/null | grep 'git-hooks' > /dev/null 2> /dev/null - if [ $? = 0 ] ; then - echo "Git hooks ARE installed in this repository." - echo "" - else - echo "Git hooks are NOT installed in this repository. (Run 'git hooks --install' to install it)" - echo "" - fi - - echo 'Listing User, Project, and Global hooks:' - echo '---' - for dir in `hook_dirs`; do - echo "${dir}:" - for hook in `list_hooks_in_dir "${dir}" 2` ; do - echo -n `basename \`dirname "${hook}"\`` - echo -e "/`basename "${hook}"` \t- `${hook} --about`" - done - echo "" - done -} - -function report_error { - echo "Hook failed: $last_run_hook" - exit 1 -} - function installglobal { TEMPLATE="$HOME/.git-template-with-git-hooks" if [ ! -d "${TEMPLATE}" ] ; then @@ -189,6 +184,11 @@ function uninstallglobal { git config --global --unset init.templatedir } +function report_error { + echo "Hook failed: $last_run_hook" + exit 1 +} + case $1 in run ) if [ ! -z "${GIT_DIR}" ] ; then -- cgit v1.2.3 From 1cf613347ef354eb75665c4e42b9ef2fdcceb84b Mon Sep 17 00:00:00 2001 From: Zearin Date: Mon, 28 Apr 2014 14:51:13 -0400 Subject: Use consistent braces for functions --- git-hooks | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/git-hooks b/git-hooks index aa55f72..8ee996a 100755 --- a/git-hooks +++ b/git-hooks @@ -162,7 +162,8 @@ git-hooks run "$0" "$@"'; fi } -function installglobal { +function installglobal +{ TEMPLATE="$HOME/.git-template-with-git-hooks" if [ ! -d "${TEMPLATE}" ] ; then DEFAULT=/usr/share/git-core/templates @@ -180,13 +181,16 @@ echo \"git hooks not installed in this repository. Run 'git hooks --install' to echo "Git global config init.templatedir is now set to ${TEMPLATE}" } -function uninstallglobal { +function uninstallglobal +{ git config --global --unset init.templatedir } -function report_error { +function report_error +{ echo "Hook failed: $last_run_hook" exit 1 + } case $1 in -- cgit v1.2.3 From e3b010c23bac87ca13fc8bd1377951e8b20726c1 Mon Sep 17 00:00:00 2001 From: Zearin Date: Mon, 28 Apr 2014 15:00:09 -0400 Subject: Use consistent function names --- git-hooks | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/git-hooks b/git-hooks index 8ee996a..ed1e66f 100755 --- a/git-hooks +++ b/git-hooks @@ -162,7 +162,7 @@ git-hooks run "$0" "$@"'; fi } -function installglobal +function install_global { TEMPLATE="$HOME/.git-template-with-git-hooks" if [ ! -d "${TEMPLATE}" ] ; then @@ -181,7 +181,7 @@ echo \"git hooks not installed in this repository. Run 'git hooks --install' to echo "Git global config init.templatedir is now set to ${TEMPLATE}" } -function uninstallglobal +function uninstall_global { git config --global --unset init.templatedir } @@ -206,10 +206,10 @@ case $1 in install_hooks "$1" ;; --installglobal ) - installglobal + install_global ;; --uninstallglobal ) - uninstallglobal + uninstall_global ;; -h|--help|-? ) echo 'Git Hooks' -- cgit v1.2.3 From 5880158d39bf29afd22b6b65244d9d33ce683624 Mon Sep 17 00:00:00 2001 From: Zearin Date: Mon, 28 Apr 2014 15:07:15 -0400 Subject: Update `--help` output * No longer using `--severalunseparatewords` (but still accepts them for backwards compatibility) * Use `` for mandatory arguments (`[square brackets]` are for optional arguments) --- git-hooks | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/git-hooks b/git-hooks index ed1e66f..096ae31 100755 --- a/git-hooks +++ b/git-hooks @@ -205,10 +205,10 @@ case $1 in --install|--uninstall ) install_hooks "$1" ;; - --installglobal ) + --install-global|--installglobal ) install_global ;; - --uninstallglobal ) + --uninstall-global|--uninstallglobal ) uninstall_global ;; -h|--help|-? ) @@ -221,13 +221,13 @@ case $1 in echo ' git hooks run [hook]. Move old hooks directory to hooks.old' echo ' --uninstall Remove existing hooks in this repository and rename hooks.old' echo ' back to hooks' - echo ' --installglobal' + echo ' --install-global' echo ' Create a template .git directory that that will be used whenever' echo ' a git repository is created or cloned that will remind the user' echo ' to install git-hooks.' - echo ' --uninstallglobal' + echo ' --uninstall-global' echo ' Turn off the global .git directory template that has the reminder.' - echo " run [cmd] Run the hooks for cmd (such as pre-commit)" + echo " run Run the hooks for (such as pre-commit)" echo " (no arguments) Show currently installed hooks" ;; * ) -- cgit v1.2.3