From cd7c6f25dcc370c9b39273a90a142422ccc0b489 Mon Sep 17 00:00:00 2001 From: mbiuki Date: Thu, 21 May 2026 17:17:52 -0400 Subject: [PATCH] fix(husky): use git -C in pre-commit hook to work with worktrees Same fix as #35800 applied to the 24.12.27 LTS branch. The hook cd's into core-web/ mid-execution and then invokes git on absolute paths to files outside core-web. In a normal clone that worked because git rediscovers the repo root from cwd. In a git worktree the calling commit sets GIT_DIR to an absolute path that the hook inherits, which makes git infer GIT_WORK_TREE from cwd (core-web) and reject absolute paths to non-core-web files. Wraps each absolute-path git invocation with `git -C "${root_dir}"`, which is unambiguous regardless of cwd or inherited GIT_DIR. No behavior change in normal-clone workflows. Refs #35799 --- core-web/.husky/pre-commit | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/core-web/.husky/pre-commit b/core-web/.husky/pre-commit index 06220484f0b1..4ff1cff9c395 100755 --- a/core-web/.husky/pre-commit +++ b/core-web/.husky/pre-commit @@ -88,7 +88,7 @@ check_sdk_client_affected() { printf "%s does not exist\n" "$dir_to_remove" fi - if ! git add "${root_dir}/dotCMS/src/main/webapp/html/js/editor-js/sdk-editor.js"; then + if ! git -C "${root_dir}" add -- "dotCMS/src/main/webapp/html/js/editor-js/sdk-editor.js"; then print_color "$RED" "Failed to stage computed sdk-client.js" exit 1 fi @@ -132,7 +132,7 @@ perform_frontend_fixes() { return 1 else printf "Completed yarn install adding yarn.lock if it was modified\n" - git add "${root_dir}/core-web/yarn.lock" + git -C "${root_dir}" add -- "core-web/yarn.lock" fi if ! yarn nx affected -t lint --exclude='tag:skip:lint' --fix=true; then @@ -151,7 +151,7 @@ perform_frontend_fixes() { for file in $files; do if echo "$modified_files" | grep -Fxq "$file"; then - if ! git add -- "${root_dir}/${file}"; then + if ! git -C "${root_dir}" add -- "${file}"; then has_errors=true fi else @@ -165,7 +165,7 @@ perform_frontend_fixes() { printf "\n" for file in "${unmatched_files[@]}"; do printf " %s\n" "${file}" - git restore "${file}" + git -C "${root_dir}" restore -- "${file}" done printf "\n" print_color "$YELLOW" "You can fix these files by running the following commands:" @@ -282,7 +282,7 @@ if [ "$backup_untracked" = true ] && [ -n "${untracked_files}" ]; then cp "${root_dir}/${file}" "${temp_dir}/${file}" # Copy the file to the temp directory, preserving the directory structure printf "Backing up %s to %s\n" "${file}" "${temp_dir}/${file}" # Restore the original file state in the repo, removing unstaged changes - git restore "${root_dir}/${file}" # Using relative path relative to current directory + git -C "${root_dir}" restore -- "${file}" # use -C to keep git rooted at repo root in worktrees fi done @@ -291,7 +291,7 @@ if [ "$backup_untracked" = true ] && [ -n "${untracked_files}" ]; then for file in $untracked_files; do if echo "${staged_files}" | grep -q "^${file}$"; then - git restore "${root_dir}/${file}" # Using relative path relative to current directory + git -C "${root_dir}" restore -- "${file}" # use -C to keep git rooted at repo root in worktrees fi done