From 85805ebf8e131b7f21f3d764690f825f167a3653 Mon Sep 17 00:00:00 2001 From: "Kyle J. McKay" Date: Thu, 21 Dec 2017 20:53:20 -0800 Subject: [PATCH] hooks: work around worktree wierdness Girocco has recently started "tolerating" linked working trees (and perhaps even non-bare repositories) just a bit better. Unfortunately that means the situation gets inflicted on the hook scripts as well. While the receive scripts are generally not expected to have to deal with the current working directory being a worktree rather than an actual Git repository directory, linked working trees introduce bizarre wierdness. One _can_ clone a linked working tree and then push back into it. Ugh. The receive hook scripts get all kinds of wierd things when this happens. Of particular concern, the current working directory will _not_ be the directory containing the `config` file! Address this travesty by resetting the current working directory and GIT_DIR variable when the ugly situation rears its head so that the hook scripts work like they are designed to. And just in case, also make sure the current directory has not been left pointing at some worktree somewhere. Signed-off-by: Kyle J. McKay --- bin/create-personal-mob-area | 18 ++++++++++++++++++ hooks/post-receive | 16 ++++++++++++++++ hooks/pre-receive | 16 ++++++++++++++++ hooks/update | 16 ++++++++++++++++ toolbox/update-all-hooks.sh | 18 ++++++++++++++++++ 5 files changed, 84 insertions(+) diff --git a/bin/create-personal-mob-area b/bin/create-personal-mob-area index 396373a..4d04c3d 100755 --- a/bin/create-personal-mob-area +++ b/bin/create-personal-mob-area @@ -32,8 +32,26 @@ fi umask 002 +relocate=\ +'# Make sure the current directory is where we expect to be +[ "${GIT_DIR+set}" != "set" ] || cd "${GIT_DIR:-.}" || exit 1 +case "${PWD%/*}" in */worktrees) + # Gah! + if + # But it COULD just be a coincidence... + [ -s commondir ] && [ -s HEAD ] && + _cmndir= && read -r _cmndir /dev/null && + [ -n "$_cmndir" ] && [ -d "$_cmndir" ] + then + # ...it is not, fix it! + cd "$_cmndir" || exit 1 + fi +esac +[ "${GIT_DIR+set}" != "set" ] || GIT_DIR="."' + write_mob_hook() { echo '#!'@shbin@ + printf '%s\n' "$relocate" echo "cd .. && GIT_DIR=. GIROCCO_PERSONAL_MOB=1 exec hooks/$1" } diff --git a/hooks/post-receive b/hooks/post-receive index 7a66b08..0231614 100755 --- a/hooks/post-receive +++ b/hooks/post-receive @@ -8,6 +8,22 @@ set -e +# Make sure the current directory is where we expect to be +[ "${GIT_DIR+set}" != "set" ] || cd "${GIT_DIR:-.}" || exit 1 +case "${PWD%/*}" in */worktrees) + # Gah! + if + # But it COULD just be a coincidence... + [ -s commondir ] && [ -s HEAD ] && + _cmndir= && read -r _cmndir /dev/null && + [ -n "$_cmndir" ] && [ -d "$_cmndir" ] + then + # ...it is not, fix it! + cd "$_cmndir" || exit 1 + fi +esac +[ "${GIT_DIR+set}" != "set" ] || GIT_DIR="." + mob=@mob@ umask 002 git config gitweb.lastchange "$(date '+%a, %d %b %Y %T %z')" || : diff --git a/hooks/pre-receive b/hooks/pre-receive index a43ee5f..d506d8e 100755 --- a/hooks/pre-receive +++ b/hooks/pre-receive @@ -6,6 +6,22 @@ set -e +# Make sure the current directory is where we expect to be +[ "${GIT_DIR+set}" != "set" ] || cd "${GIT_DIR:-.}" || exit 1 +case "${PWD%/*}" in */worktrees) + # Gah! + if + # But it COULD just be a coincidence... + [ -s commondir ] && [ -s HEAD ] && + _cmndir= && read -r _cmndir /dev/null && + [ -n "$_cmndir" ] && [ -d "$_cmndir" ] + then + # ...it is not, fix it! + cd "$_cmndir" || exit 1 + fi +esac +[ "${GIT_DIR+set}" != "set" ] || GIT_DIR="." + umask 002 if [ -x @perlbin@ ]; then diff --git a/hooks/update b/hooks/update index f7d86b8..f46f92a 100755 --- a/hooks/update +++ b/hooks/update @@ -6,6 +6,22 @@ set -e +# Make sure the current directory is where we expect to be +[ "${GIT_DIR+set}" != "set" ] || cd "${GIT_DIR:-.}" || exit 1 +case "${PWD%/*}" in */worktrees) + # Gah! + if + # But it COULD just be a coincidence... + [ -s commondir ] && [ -s HEAD ] && + _cmndir= && read -r _cmndir /dev/null && + [ -n "$_cmndir" ] && [ -d "$_cmndir" ] + then + # ...it is not, fix it! + cd "$_cmndir" || exit 1 + fi +esac +[ "${GIT_DIR+set}" != "set" ] || GIT_DIR="." + if ! [ -x @perlbin@ ]; then # We are INSIDE the chroot diff --git a/toolbox/update-all-hooks.sh b/toolbox/update-all-hooks.sh index 53f25e6..30a3761 100755 --- a/toolbox/update-all-hooks.sh +++ b/toolbox/update-all-hooks.sh @@ -21,8 +21,26 @@ fi umask 002 +relocate=\ +'# Make sure the current directory is where we expect to be +[ "${GIT_DIR+set}" != "set" ] || cd "${GIT_DIR:-.}" || exit 1 +case "${PWD%/*}" in */worktrees) + # Gah! + if + # But it COULD just be a coincidence... + [ -s commondir ] && [ -s HEAD ] && + _cmndir= && read -r _cmndir /dev/null && + [ -n "$_cmndir" ] && [ -d "$_cmndir" ] + then + # ...it is not, fix it! + cd "$_cmndir" || exit 1 + fi +esac +[ "${GIT_DIR+set}" != "set" ] || GIT_DIR="."' + write_mob_hook() { echo '#!'@shbin@ + printf '%s\n' "$relocate" echo "cd .. && GIT_DIR=. GIROCCO_PERSONAL_MOB=1 exec hooks/$1" } -- 2.11.4.GIT