This is an automated email from the ASF dual-hosted git repository.
cryptoe pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/druid.git
The following commit(s) were added to refs/heads/master by this push:
new e40df5301e8 dev: make git hooks work from linked worktrees (#20477)
e40df5301e8 is described below
commit e40df5301e8d15c510a0374dbdf9c7414ba05d43
Author: Andreas Maechler <[email protected]>
AuthorDate: Tue Oct 6 17:50:52 2026 -0600
dev: make git hooks work from linked worktrees (#20477)
* Make git hooks work from linked worktrees
In a linked worktree, .git is a file pointing at .git/worktrees/<name>,
so the hooks' relative .git/hooks/... paths fail with "Not a directory"
and both commit and push are blocked.
pre-commit and pre-push now locate run-all-in-dir.py and the hook
directories next to themselves via $0, which git sets to the hook's own
path. This also works when core.hooksPath is set. install-hooks.sh and
uninstall-hooks.sh resolve the hooks directory with
git rev-parse --git-common-dir instead of assuming ${DRUID_ROOT}/.git.
* Infer DRUID_ROOT and respect core.hooksPath in hook installers
* Install hooks into the git common dir instead of following core.hooksPath
---
hooks/install-hooks.sh | 21 ++++++++-------------
hooks/pre-commit | 3 ++-
hooks/pre-push | 3 ++-
hooks/uninstall-hooks.sh | 15 +++++----------
4 files changed, 17 insertions(+), 25 deletions(-)
diff --git a/hooks/install-hooks.sh b/hooks/install-hooks.sh
index 62e0fc843a5..76a3f6adc1c 100755
--- a/hooks/install-hooks.sh
+++ b/hooks/install-hooks.sh
@@ -25,17 +25,12 @@ function cp_if_not_exist(){
fi
}
-if [ $# != 1 ]
- then
- echo 'usage: program {$DRUID_ROOT}'
- exit 1
-fi
+DRUID_ROOT="${1:-$(dirname "$0")/..}"
+GIT_HOOKS_DIR="$(git -C "${DRUID_ROOT}" rev-parse --path-format=absolute
--git-common-dir)/hooks"
-DRUID_ROOT=$1
-
-mkdir -p ${DRUID_ROOT}/.git/hooks
-cp_if_not_exist ${DRUID_ROOT}/hooks/run-all-in-dir.py
${DRUID_ROOT}/.git/hooks/run-all-in-dir.py
-cp_if_not_exist ${DRUID_ROOT}/hooks/pre-commit
${DRUID_ROOT}/.git/hooks/pre-commit
-cp_if_not_exist ${DRUID_ROOT}/hooks/pre-push ${DRUID_ROOT}/.git/hooks/pre-push
-cp_if_not_exist ${DRUID_ROOT}/hooks/pre-commits
${DRUID_ROOT}/.git/hooks/pre-commits
-cp_if_not_exist ${DRUID_ROOT}/hooks/pre-pushes
${DRUID_ROOT}/.git/hooks/pre-pushes
+mkdir -p "${GIT_HOOKS_DIR}"
+cp_if_not_exist "${DRUID_ROOT}/hooks/run-all-in-dir.py"
"${GIT_HOOKS_DIR}/run-all-in-dir.py"
+cp_if_not_exist "${DRUID_ROOT}/hooks/pre-commit" "${GIT_HOOKS_DIR}/pre-commit"
+cp_if_not_exist "${DRUID_ROOT}/hooks/pre-push" "${GIT_HOOKS_DIR}/pre-push"
+cp_if_not_exist "${DRUID_ROOT}/hooks/pre-commits"
"${GIT_HOOKS_DIR}/pre-commits"
+cp_if_not_exist "${DRUID_ROOT}/hooks/pre-pushes" "${GIT_HOOKS_DIR}/pre-pushes"
diff --git a/hooks/pre-commit b/hooks/pre-commit
index 6cfd4b962e5..aaa355a5312 100755
--- a/hooks/pre-commit
+++ b/hooks/pre-commit
@@ -15,4 +15,5 @@
# See the License for the specific language governing permissions and
# limitations under the License.
-.git/hooks/run-all-in-dir.py .git/hooks/pre-commits
\ No newline at end of file
+HOOKS_DIR="$(dirname "$0")"
+"${HOOKS_DIR}/run-all-in-dir.py" "${HOOKS_DIR}/pre-commits"
diff --git a/hooks/pre-push b/hooks/pre-push
index 40c40db1209..4ffcb658a21 100755
--- a/hooks/pre-push
+++ b/hooks/pre-push
@@ -19,4 +19,5 @@
# under the License.
#
-.git/hooks/run-all-in-dir.py .git/hooks/pre-pushes $1 $2
\ No newline at end of file
+HOOKS_DIR="$(dirname "$0")"
+"${HOOKS_DIR}/run-all-in-dir.py" "${HOOKS_DIR}/pre-pushes" "$@"
diff --git a/hooks/uninstall-hooks.sh b/hooks/uninstall-hooks.sh
index e118eb05d90..db52c3bf401 100755
--- a/hooks/uninstall-hooks.sh
+++ b/hooks/uninstall-hooks.sh
@@ -19,19 +19,14 @@
# under the License.
#
-if [ $# != 1 ]
- then
- echo 'usage: program {$DRUID_ROOT}'
- exit 1
-fi
-
-DRUID_ROOT=$1
+DRUID_ROOT="${1:-$(dirname "$0")/..}"
+GIT_HOOKS_DIR="$(git -C "${DRUID_ROOT}" rev-parse --path-format=absolute
--git-common-dir)/hooks"
# This script does not remove .git/hooks/pre-commit, .git/hooks/pre-push, or
any other git hook scripts
# because those files may have user-custom hooks.
# Instead, we remove only the files and directories that we are sure it is
safe to remove.
-rm -f ${DRUID_ROOT}/.git/hooks/run-all-in-dir.py
-rm -rf ${DRUID_ROOT}/.git/hooks/pre-commits
-rm -rf ${DRUID_ROOT}/.git/hooks/pre-pushes
+rm -f "${GIT_HOOKS_DIR}/run-all-in-dir.py"
+rm -rf "${GIT_HOOKS_DIR}/pre-commits"
+rm -rf "${GIT_HOOKS_DIR}/pre-pushes"
echo "This script does not remove or modify the git hook script files in
.git/hooks, such as 'pre-commit' or 'pre-push'. Those scripts should be removed
or modified manually."
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]