diff --git a/core-web/.husky/pre-commit b/core-web/.husky/pre-commit index 51b44d6ea173..3190474c323f 100755 --- a/core-web/.husky/pre-commit +++ b/core-web/.husky/pre-commit @@ -80,7 +80,7 @@ check_sdk_client_affected() { print_color "$BLUE" "â„šī¸ ${file_to_remove} does not exist" fi - if ! git add "${root_dir}/dotCMS/src/main/webapp/ext/uve/dot-uve.js"; then + if ! git -C "${root_dir}" add -- "dotCMS/src/main/webapp/ext/uve/dot-uve.js"; then print_color "$RED" "❌ Failed to stage computed dot-uve.js" exit 1 fi @@ -124,7 +124,7 @@ perform_frontend_fixes() { return 1 else print_color "$GREEN" "✅ Completed yarn install adding yarn.lock if it was modified" - 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 @@ -143,7 +143,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 @@ -157,7 +157,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:" @@ -303,7 +303,7 @@ if needs_maven; then print_color "$GREEN" "✅ Completed Maven compile with OpenAPI generation" # Stage the updated OpenAPI file if it was regenerated if [ -f "${root_dir}/dotCMS/src/main/webapp/WEB-INF/openapi/openapi.yaml" ]; then - git add "${root_dir}/dotCMS/src/main/webapp/WEB-INF/openapi/openapi.yaml" + git -C "${root_dir}" add -- "dotCMS/src/main/webapp/WEB-INF/openapi/openapi.yaml" print_color "$GREEN" "📋 Updated OpenAPI specification staged for commit" fi fi @@ -384,7 +384,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 print_color "$BLUE" "💾 Backing up ${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 @@ -393,7 +393,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