From d8aa56ace831bcb018e55b38248e424179988614 Mon Sep 17 00:00:00 2001 From: "Kyle J. McKay" Date: Fri, 22 Dec 2017 00:01:25 -0800 Subject: [PATCH] hooks: find ourselves before seeking elsewhere Two of the mob hook scripts simply redirect to the same-named hook scripts in the non-mob repository (pre-receive and post-receive). They have been assuming that the script to hand off to (via exec) can be found in the $PWD/../hooks directory. But now, with the hand of friendship (reluctant tolerance) extended to linked working trees, all sorts of wierd **** can happen. Instead of relying on the value of the current working directory, use the actual script's location (as determined using a combination of the current working directory and $0) as the starting point to locate the script to hand off to. Since the scripts themselves will always be in the same location no matter what kind of repository (bare, non-bare, main working tree, linked working tree, local, remote) is involved, this provides a much more reliable technique that works for every access method. Signed-off-by: Kyle J. McKay --- bin/create-personal-mob-area | 3 ++- toolbox/update-all-hooks.sh | 3 ++- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/bin/create-personal-mob-area b/bin/create-personal-mob-area index 4d04c3d..1160f62 100755 --- a/bin/create-personal-mob-area +++ b/bin/create-personal-mob-area @@ -51,8 +51,9 @@ esac write_mob_hook() { echo '#!'@shbin@ + echo 'mydir="${0%/*}" && : "${mydir:=.}" && mydir="$(cd "$mydir" && pwd -P)" || exit 1' printf '%s\n' "$relocate" - echo "cd .. && GIT_DIR=. GIROCCO_PERSONAL_MOB=1 exec hooks/$1" + echo 'cd .. && GIT_DIR=. GIROCCO_PERSONAL_MOB=1 exec "$mydir/../../hooks/${0##*/}"' } mkdir -p "$projdir/refs/mob" "$projdir/mob/refs" "$projdir/mob/hooks" diff --git a/toolbox/update-all-hooks.sh b/toolbox/update-all-hooks.sh index 30a3761..0714f6b 100755 --- a/toolbox/update-all-hooks.sh +++ b/toolbox/update-all-hooks.sh @@ -40,8 +40,9 @@ esac write_mob_hook() { echo '#!'@shbin@ + echo 'mydir="${0%/*}" && : "${mydir:=.}" && mydir="$(cd "$mydir" && pwd -P)" || exit 1' printf '%s\n' "$relocate" - echo "cd .. && GIT_DIR=. GIROCCO_PERSONAL_MOB=1 exec hooks/$1" + echo 'cd .. && GIT_DIR=. GIROCCO_PERSONAL_MOB=1 exec "$mydir/../../hooks/${0##*/}"' } base="${cfg_reporoot%/}" -- 2.11.4.GIT