diff options
author | Georg Lutz <georg@georglutz.de> | 2013-08-24 20:17:11 +0200 |
---|---|---|
committer | Benjamin C Meyer <ben@meyerhome.net> | 2013-10-20 22:14:26 -0400 |
commit | 187f23820f43e962acbeab788d5a96d5d59bd51e (patch) | |
tree | 6dab2087cbcc058d08cb9927ebae996f0dbd8b8c | |
parent | 600bd81f37a059c4a16eb48fa8838750bea48e5a (diff) | |
download | git-hooks-187f23820f43e962acbeab788d5a96d5d59bd51e.tar.gz git-hooks-187f23820f43e962acbeab788d5a96d5d59bd51e.tar.bz2 |
Fix too many hooks reported in list_hooks_in_dir
list_hooks_in_dir should report exactly the hooks that would be run with
run_hooks. But the find command in list_hooks_in_dir does not limit itself to
the scheme "folder_name/hook_name" but recurses infinitely through sub
directories reporting all executable files. If your hooks are stored itself in
a git repository then consequently also the files in .git/hooks are reported.
This change sets the search depth exactly to two, so that the correct scripts
are reported, e.g. :
~/.git_hooks/commit-msg/script1
but not e.g. :
~/.git_hook/.git/hooks/commit-msg
~/.git_hooks/script2
~/.git_hooks/commit-msg/dir2/script3
Signed-off-by: Benjamin C Meyer <ben@meyerhome.net>
-rwxr-xr-x | git-hooks | 8 |
1 files changed, 5 insertions, 3 deletions
@@ -43,7 +43,9 @@ function hook_dirs function list_hooks_in_dir { - find -L "${1}/" -perm +111 -type f 2>/dev/null | grep -v "^.$" | sort + path="${1}" + level="${2}" + find -L "${path}/" -mindepth ${level} -maxdepth ${level} -perm +111 -type f 2>/dev/null | grep -v "^.$" | sort } function run_hooks @@ -54,7 +56,7 @@ function run_hooks return 1 fi shift 1 - for hook in `list_hooks_in_dir "${dir}"` + for hook in `list_hooks_in_dir "${dir}" 1` do export last_run_hook="${hook} $@" if [ ! -z ${GIT_HOOKS_VERBOSE} ] ; then @@ -132,7 +134,7 @@ function list_hooks echo '---' for dir in `hook_dirs`; do echo "${dir}:" - for hook in `list_hooks_in_dir "${dir}"` ; do + for hook in `list_hooks_in_dir "${dir}" 2` ; do echo -n `basename \`dirname "${hook}"\`` echo -e "/`basename "${hook}"` \t- `${hook} --about`" done |