From e97aebd8fed255507fd17ef37a06b042ebed7e77 Mon Sep 17 00:00:00 2001 From: Paul Eggert Date: Tue, 15 Aug 2017 13:31:03 -0700 Subject: [PATCH] Do not assume regular Git .git/hooks dir MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Apparently Gitlab doesn’t create .git/hooks, like regular Git does. Problem reported by Ted Zlatanov in: http://lists.gnu.org/archive/html/emacs-devel/2017-08/msg00380.html * autogen.sh (git_sample_hook_src): New function. Use it to work even if .git/hooks or its samples do not exist. --- autogen.sh | 23 +++++++++++++++++++++-- 1 file changed, 21 insertions(+), 2 deletions(-) diff --git a/autogen.sh b/autogen.sh index 70f9cbd..d454e41 100755 --- a/autogen.sh +++ b/autogen.sh @@ -327,8 +327,21 @@ sample_hooks= cmp -- build-aux/git-hooks/$hook "$hooks/$hook" >/dev/null 2>&1 || tailored_hooks="$tailored_hooks $hook" done + +git_sample_hook_src () +{ + hook=$1 + src=$hooks/$hook.sample + if test ! -r "$src"; then + case $hook in + applypatch-msg) src=build-aux/git-hooks/commit-msg;; + pre-applypatch) src=build-aux/git-hooks/pre-commit;; + esac + fi +} for hook in applypatch-msg pre-applypatch; do - cmp -- "$hooks/$hook.sample" "$hooks/$hook" >/dev/null 2>&1 || + git_sample_hook_src $hook + cmp -- "$src" "$hooks/$hook" >/dev/null 2>&1 || sample_hooks="$sample_hooks $hook" done @@ -336,6 +349,11 @@ sample_hooks= if $do_git; then echo "Installing git hooks..." + if test ! -d "$hooks"; then + printf "mkdir -p -- '%s'\\n" "$hooks" + mkdir -p -- "$hooks" || exit + fi + if test -n "$tailored_hooks"; then for hook in $tailored_hooks; do dst=$hooks/$hook @@ -346,8 +364,9 @@ sample_hooks= if test -n "$sample_hooks"; then for hook in $sample_hooks; do + git_sample_hook_src $hook dst=$hooks/$hook - cp $cp_options -- "$dst.sample" "$dst" || exit + cp $cp_options -- "$src" "$dst" || exit chmod -- a-w "$dst" || exit done fi -- 2.7.4