From 52eac400066ac30dda6a86cd23c7e9351ceec015 Mon Sep 17 00:00:00 2001 From: Mara Averick Date: Fri, 17 Apr 2026 08:14:04 -0600 Subject: [PATCH 1/3] fix(git-hooks): resolve hooks-cache path in worktrees and submodules MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Fix `pre-commit`, `pre-push`, and `commit-msg` hooks assumption that `${root}/.git` is a directory (not true for worktrees and submodules). Use `git rev-parse` to resolve the git directory rather than path-joining onto `${root}/.git`, so the hooks work in any repo layout git supports — linked worktrees and submodules both put a gitfile at `${root}/.git` and fail under the old assumption. Fixes: https://github.com/stdlib-js/stdlib/issues/11500 Assisted-by: Claude Opus 4.7 --- tools/git/hooks/commit-msg | 5 ++++- tools/git/hooks/pre-commit | 5 ++++- tools/git/hooks/pre-push | 5 ++++- 3 files changed, 12 insertions(+), 3 deletions(-) diff --git a/tools/git/hooks/commit-msg b/tools/git/hooks/commit-msg index c6ebcf342f17..e7f7bf45ad16 100644 --- a/tools/git/hooks/commit-msg +++ b/tools/git/hooks/commit-msg @@ -36,8 +36,11 @@ commit_message="$1" # Determine root directory: root=$(git rev-parse --show-toplevel) +# Determine git directory (resolves where `${root}/.git` is file OR directory): +git_dir=$(git rev-parse --absolute-git-dir) + # Define the path to a report generated during the pre-commit hook: -pre_commit_report="${root}/.git/hooks-cache/pre_commit_report.yml" +pre_commit_report="${git_dir}/hooks-cache/pre_commit_report.yml" # FUNCTIONS # diff --git a/tools/git/hooks/pre-commit b/tools/git/hooks/pre-commit index 863afb345236..6153570f94e2 100644 --- a/tools/git/hooks/pre-commit +++ b/tools/git/hooks/pre-commit @@ -50,6 +50,9 @@ skip_editorconfig="${SKIP_LINT_EDITORCONFIG}" # Determine root directory: root=$(git rev-parse --show-toplevel) +# Determine git directory (resolves where `${root}/.git` is file OR directory): +git_dir=$(git rev-parse --absolute-git-dir) + # Define the path to a utility for linting filenames: lint_filenames="${root}/lib/node_modules/@stdlib/_tools/lint/filenames/bin/cli" @@ -81,7 +84,7 @@ cppcheck_tests_fixtures_suppressions_list="${root}/etc/cppcheck/suppressions.tes cppcheck_benchmarks_suppressions_list="${root}/etc/cppcheck/suppressions.benchmarks.txt" # Define the path to a directory for caching hook results: -cache_dir="${root}/.git/hooks-cache" +cache_dir="${git_dir}/hooks-cache" # Define the path to a file for storing hook results: cache_file="${cache_dir}/pre_commit_report.yml" diff --git a/tools/git/hooks/pre-push b/tools/git/hooks/pre-push index 57f2d9f7dafe..3de4b5f06405 100755 --- a/tools/git/hooks/pre-push +++ b/tools/git/hooks/pre-push @@ -59,8 +59,11 @@ GIT_CURRENT_BRANCH=$(git rev-parse --abbrev-ref HEAD) # Determine root directory: root=$(git rev-parse --show-toplevel) +# Determine git directory (resolves where `${root}/.git` is file OR directory): +git_dir=$(git rev-parse --absolute-git-dir) + # Define the path to a directory for caching hook results: -cache_dir="${root}/.git/hooks-cache" +cache_dir="${git_dir}/hooks-cache" # Define the path to a file for storing hook results: cache_file="${cache_dir}/pre_push_report.yml" From e147d1d4f2768c800bd810d3dada4c54b2475581 Mon Sep 17 00:00:00 2001 From: Mara Averick Date: Fri, 17 Apr 2026 08:58:00 -0600 Subject: [PATCH 2/3] fix: remove unused `root` variable from `commit-msg` hook The `commit-msg` hook never referenced `${root}`. Touching the file for the worktree fix surfaced the pre-existing SC2034 warning; remove the dead line rather than carrying it forward. --- tools/git/hooks/commit-msg | 3 --- 1 file changed, 3 deletions(-) diff --git a/tools/git/hooks/commit-msg b/tools/git/hooks/commit-msg index e7f7bf45ad16..241eab41ff00 100644 --- a/tools/git/hooks/commit-msg +++ b/tools/git/hooks/commit-msg @@ -33,9 +33,6 @@ skip_lint="${SKIP_LINT_COMMIT}" # Get the path to a file containing the commit message: commit_message="$1" -# Determine root directory: -root=$(git rev-parse --show-toplevel) - # Determine git directory (resolves where `${root}/.git` is file OR directory): git_dir=$(git rev-parse --absolute-git-dir) From 89216b3e339be4d1046b83f08836ac86a8cfc71b Mon Sep 17 00:00:00 2001 From: Athan Date: Fri, 17 Apr 2026 13:46:40 -0700 Subject: [PATCH 3/3] Apply suggestions from code review Co-authored-by: Athan Signed-off-by: Athan --- tools/git/hooks/commit-msg | 2 +- tools/git/hooks/pre-commit | 2 +- tools/git/hooks/pre-push | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/tools/git/hooks/commit-msg b/tools/git/hooks/commit-msg index 241eab41ff00..4f7a69951752 100644 --- a/tools/git/hooks/commit-msg +++ b/tools/git/hooks/commit-msg @@ -33,7 +33,7 @@ skip_lint="${SKIP_LINT_COMMIT}" # Get the path to a file containing the commit message: commit_message="$1" -# Determine git directory (resolves where `${root}/.git` is file OR directory): +# Resolve the location of the Git directory: git_dir=$(git rev-parse --absolute-git-dir) # Define the path to a report generated during the pre-commit hook: diff --git a/tools/git/hooks/pre-commit b/tools/git/hooks/pre-commit index 6153570f94e2..d5020bfbd6fe 100644 --- a/tools/git/hooks/pre-commit +++ b/tools/git/hooks/pre-commit @@ -50,7 +50,7 @@ skip_editorconfig="${SKIP_LINT_EDITORCONFIG}" # Determine root directory: root=$(git rev-parse --show-toplevel) -# Determine git directory (resolves where `${root}/.git` is file OR directory): +# Resolve the location of the Git directory: git_dir=$(git rev-parse --absolute-git-dir) # Define the path to a utility for linting filenames: diff --git a/tools/git/hooks/pre-push b/tools/git/hooks/pre-push index 3de4b5f06405..2a077010b9ae 100755 --- a/tools/git/hooks/pre-push +++ b/tools/git/hooks/pre-push @@ -59,7 +59,7 @@ GIT_CURRENT_BRANCH=$(git rev-parse --abbrev-ref HEAD) # Determine root directory: root=$(git rev-parse --show-toplevel) -# Determine git directory (resolves where `${root}/.git` is file OR directory): +# Resolve the location of the Git directory: git_dir=$(git rev-parse --absolute-git-dir) # Define the path to a directory for caching hook results: