You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@druid.apache.org by "amaechler (via GitHub)" <gi...@apache.org> on 2026/10/02 21:19:02 UTC
[PR] Make git hooks work from linked worktrees (druid)
amaechler opened a new pull request, #20477:
URL: https://github.com/apache/druid/pull/20477
The git hooks don't work from a linked git worktree. There, `.git` is a file (`gitdir: .../.git/worktrees/<name>`), not a directory, so the hooks' relative `.git/hooks/...` paths fail and block every commit and push. `install-hooks.sh` and `uninstall-hooks.sh` fail the same way. With many agents working in worktrees by default, this is a much more common scneario nowadays (my local Claude basically just always passes `--no-verify` to skip the hooks).
Before:
```sh
$ git worktree add ../druid-wt -b feature && cd ../druid-wt
$ git commit -m test
.git/hooks/pre-commit: line 18: .git/hooks/run-all-in-dir.py: Not a directory
$ hooks/install-hooks.sh .
mkdir: ./.git: Not a directory
```
After:
```
$ git commit -m test
[feature 293a5b3] test
```
This picks up #17706 without the `eval`:
- `pre-commit` and `pre-push` find their helper files next to themselves via `$0`, which git sets to the hook's own path. This needs no git call and also works when `core.hooksPath` is set.
- `install-hooks.sh` and `uninstall-hooks.sh` find the hooks folder with `git rev-parse --git-common-dir` instead of assuming `.git/hooks`. This needs git 2.31 or newer.
- Paths are quoted, and `pre-push` forwards `"$@"`.
If you already have the hooks installed, the installer won't overwrite them. To pick up the fix, delete `.git/hooks/pre-commit` and `.git/hooks/pre-push`, then run `hooks/uninstall-hooks.sh .` and `hooks/install-hooks.sh .`.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@druid.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@druid.apache.org
For additional commands, e-mail: commits-help@druid.apache.org
Re: [PR] dev: make git hooks work from linked worktrees (druid)
Posted by "amaechler (via GitHub)" <gi...@apache.org>.
amaechler commented on code in PR #20477:
URL: https://github.com/apache/druid/pull/20477#discussion_r4175962385
##########
hooks/install-hooks.sh:
##########
@@ -32,10 +32,11 @@ if [ $# != 1 ]
fi
DRUID_ROOT=$1
+GIT_HOOKS_DIR="$(git -C "${DRUID_ROOT}" rev-parse --path-format=absolute --git-common-dir)/hooks"
Review Comment:
Reverting this. Following `core.hooksPath` means a global hooks path gets Druid's hooks, so pushes from unrelated repos run `checkstyle-check`, and `core.hooksPath=hooks` points the uninstaller at the tracked sources (the P1 below). Both scripts go back to `--git-common-dir`, which handles linked worktrees. If you use `core.hooksPath`, you can now point it at the tracked hooks with `git config core.hooksPath hooks`; they find their helpers through `$0` and need no install step.
##########
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-path 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"
Review Comment:
Agreed, this came from following `core.hooksPath`. Reverted to `--git-common-dir`, so both scripts only touch this repo's `.git/hooks`, as before this PR.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@druid.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@druid.apache.org
For additional commands, e-mail: commits-help@druid.apache.org
Re: [PR] dev: make git hooks work from linked worktrees (druid)
Posted by "amaechler (via GitHub)" <gi...@apache.org>.
amaechler commented on code in PR #20477:
URL: https://github.com/apache/druid/pull/20477#discussion_r4174563360
##########
hooks/install-hooks.sh:
##########
Review Comment:
Good call, `dev/intellij-setup.md` already says to run it without an argument. `DRUID_ROOT` now defaults to the script's parent directory, so `hooks/install-hooks.sh` works from any directory. Passing a path still works. Same change in `uninstall-hooks.sh`.
##########
hooks/install-hooks.sh:
##########
@@ -32,10 +32,11 @@ if [ $# != 1 ]
fi
DRUID_ROOT=$1
+GIT_HOOKS_DIR="$(git -C "${DRUID_ROOT}" rev-parse --path-format=absolute --git-common-dir)/hooks"
Review Comment:
Fixed, both scripts now use `git rev-parse --path-format=absolute --git-path hooks`. It still resolves to the shared hooks folder from a linked worktree, and it follows `core.hooksPath`, both relative and absolute. One thing to know: with a global `core.hooksPath`, the hooks get installed into that global folder, because that's where git runs hooks from. `cp_if_not_exist` still won't overwrite an existing `pre-commit` or `pre-push` there.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@druid.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@druid.apache.org
For additional commands, e-mail: commits-help@druid.apache.org
Re: [PR] dev: make git hooks work from linked worktrees (druid)
Posted by "FrankChen021 (via GitHub)" <gi...@apache.org>.
FrankChen021 commented on code in PR #20477:
URL: https://github.com/apache/druid/pull/20477#discussion_r4171412322
##########
hooks/install-hooks.sh:
##########
Review Comment:
I didn't run this script for long, and I remember initially we didn't need to provide this argument. I checked the change history, #12300 introduced this requirement. Current document also does not mention this argument either.
However, I think this DRUID_ROOT can be inferred from running dir, and if it's not able to infer, then we can exit the script with the usage help text
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@druid.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@druid.apache.org
For additional commands, e-mail: commits-help@druid.apache.org
Re: [PR] dev: make git hooks work from linked worktrees (druid)
Posted by "cryptoe (via GitHub)" <gi...@apache.org>.
cryptoe merged PR #20477:
URL: https://github.com/apache/druid/pull/20477
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@druid.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@druid.apache.org
For additional commands, e-mail: commits-help@druid.apache.org
Re: [PR] dev: make git hooks work from linked worktrees (druid)
Posted by "FrankChen021 (via GitHub)" <gi...@apache.org>.
FrankChen021 commented on code in PR #20477:
URL: https://github.com/apache/druid/pull/20477#discussion_r4173105628
##########
hooks/install-hooks.sh:
##########
@@ -32,10 +32,11 @@ if [ $# != 1 ]
fi
DRUID_ROOT=$1
+GIT_HOOKS_DIR="$(git -C "${DRUID_ROOT}" rev-parse --path-format=absolute --git-common-dir)/hooks"
Review Comment:
[P2] Respect configured core.hooksPath
**Finding:** When a repository sets core.hooksPath, Git executes hooks from that configured directory, but this installer always copies the wrappers and helper directories into the common repository's .git/hooks. The documented installer therefore leaves the configured hook path empty, so commits and pushes bypass these checks (and uninstall likewise targets the unused directory).
**Suggestion:** Resolve the destination with Git's configured hooks path, such as the absolute form of rev-parse --git-path hooks, in both scripts.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@druid.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@druid.apache.org
For additional commands, e-mail: commits-help@druid.apache.org
Re: [PR] dev: make git hooks work from linked worktrees (druid)
Posted by "FrankChen021 (via GitHub)" <gi...@apache.org>.
FrankChen021 commented on code in PR #20477:
URL: https://github.com/apache/druid/pull/20477#discussion_r4175793798
##########
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-path 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"
Review Comment:
[P1] Avoid deleting unowned shared hook directories
**Finding:** Because GIT_HOOKS_DIR now follows core.hooksPath, it can be a global/shared hooks directory—or the repository's tracked hooks/ directory. The unconditional recursive removal of pre-commits (and the analogous pre-pushes removal) can delete hook directories owned by another repository or tracked Druid sources when uninstall-hooks.sh is run, causing data loss and leaving hooks broken.
**Suggestion:** Track ownership of installed files and directories and only remove entries created by this installer; at minimum, refuse to uninstall when the resolved hooks path is shared or overlaps the source hooks tree.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@druid.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@druid.apache.org
For additional commands, e-mail: commits-help@druid.apache.org