LTS pre-commit hook fails in git worktrees on non-core-web changes
Nobody has claimed this yet.
- Dominant language
- Java
- Stars
- 970
- Forks
- 486
- Avg merge
- 3d 33m
- Merged PRs (30d)
- 170
Description
Symptom
On both release-24.12.27_lts and release-25.07.10_lts, attempting to git commit a change outside the core-web/ subtree from inside a git worktree (as opposed to a normal clone) fails with:
[FIPS …] (irrelevant prelude truncated)
📁 Created temporary directory /var/folders/.../tmp.XXXXXX
💾 Backing up parent/pom.xml
fatal: /private/tmp/<worktree>/parent/pom.xml: '/private/tmp/<worktree>/parent/pom.xml' is outside repository at '/private/tmp/<worktree>/core-web'
husky - pre-commit hook exited with code 128 (error)
The hook never reaches its actual lint/format work — it dies in the file-backup step.
Root cause
In core-web/.husky/pre-commit:
- Line 355
cd "${core_web_dir}" || exit 1switches cwd tocore-web/. - Line 387
git restore "${root_dir}/${file}"then invokes git from insidecore-web/, passing an absolute path to a file outside that subtree.
In a normal clone this is harmless: git's repo-discovery walks up from cwd and finds the .git/ directory at the repo root, and git restore operates on the absolute path correctly.
In a git worktree the calling git commit sets GIT_DIR to an absolute path (e.g. /Users/.../core/.git/worktrees/<name>). That env var is inherited by the hook process and every subprocess. When git is then invoked from core-web/ with GIT_DIR already set, git skips its normal .git discovery and infers GIT_WORK_TREE from cwd → core-web/. The absolute path argument .../<worktree>/parent/pom.xml is then judged "outside repository at .../core-web", producing the fatal.
The same dependency on cwd applies to the other in-hook git add / git restore calls in perform_frontend_fixes (lines 132, 150, 167) — anywhere the hook passes an absolute path while running from a different cwd in a worktree.
Main branch is not affected — its hook is a different version with a graceful skip when the toolchain isn't bootstrapped.
Reproduction
cd ~/path/to/dotCMS/core
git worktree add -b feature/example /tmp/lts-wt origin/release-25.07.10_lts
cd /tmp/lts-wt
# touch any non-core-web file and stage it
echo '<!-- test -->' >> parent/pom.xml
git add parent/pom.xml
git commit -m "test"
# → husky pre-commit dies as above
Impact
- Breaks the standard worktree-based development workflow for LTS branches.
- Forced workaround for #35797 and #35798 (Tomcat bump backports): use fresh shallow clones rather than worktrees. Slower, more disk, no
git worktree listtraceability. - Will block any future LTS backports done via worktrees until fixed.
Proposed fix
Replace the cwd-dependent absolute-path git invocations with git -C "${root_dir}" form, which is unambiguous regardless of cwd or GIT_DIR. Minimal patch:
- git restore "${root_dir}/${file}"
+ git -C "${root_dir}" restore -- "${file}"
- if ! git add -- "${root_dir}/${file}"; then
+ if ! git -C "${root_dir}" add -- "${file}"; then
- git restore "${file}"
+ git -C "${root_dir}" restore -- "${file}"
- git add "${root_dir}/core-web/yarn.lock"
+ git -C "${root_dir}" add -- "core-web/yarn.lock"
(Exact line numbers in core-web/.husky/pre-commit.)
Branches that need the fix:
-
release-25.07.10_lts -
release-24.12.27_lts
main is unaffected.
Suggested companion improvement (out of scope here)
The hook's cd "${core_web_dir}" exists so that yarn / nx commands resolve relative to core-web/. After this fix, that cd is still needed for those subcommands, but the hook should treat the cd as a local scope rather than a global state change — easy to confirm with a comment near the cd line.
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start in core-web/.husky/pre-commit, especially the git add and git restore calls at lines 132, 150, 167, and 387. Reproduce the failure from a git worktree on an LTS branch, then verify the hook's backup, restore, and staging steps work for non-core-web changes on both listed branches.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- git, shell
- Domain
- developer-experience, tooling
- Issue type
- Bug
- Difficulty
- 2/5
- Estimated time
- 1-3 hours
- Activity status
- Quiet
- Clarity
- Clearly specified
- Newbie friendliness
- 82/100