feat(ci): require bash >= 4.2 in the pre-commit hook scripts - #3837
Open
ethanlin01x wants to merge 4 commits into
Open
feat(ci): require bash >= 4.2 in the pre-commit hook scripts#3837ethanlin01x wants to merge 4 commits into
ethanlin01x wants to merge 4 commits into
Conversation
On macOS `#!/bin/bash` always resolves to the system bash 3.2, so a script pinned to it cannot pick up a newer bash a contributor installed. Resolving bash from PATH instead is a prerequisite for gating on a minimum version. Scripts that only ever run inside one image keep the absolute path.
Supporting bash 3.2 means writing every hook script against a shell that predates mapfile and associative arrays, and the fallbacks it forces are harder to read than what they replace. Kubernetes solved this by refusing to run and pointing macOS users at `brew install bash`. Do the same here. The check lives in a sourced lib rather than a single leading hook so that it also covers running a script straight from the CLI. Sourcing it runs the check, following hack/lib/init.sh, so a second check reaches all thirteen hooks by being added in one place. The error names the resolved interpreter, because a git GUI can hand a hook a PATH where /bin still wins.
ethanlin01x
marked this pull request as ready for review
August 7, 2026 15:40
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## master #3837 +/- ##
============================================
- Coverage 76.58% 75.84% -0.74%
Complexity 1046 1046
============================================
Files 1347 1337 -10
Lines 171018 169763 -1255
Branches 142372 142442 +70
============================================
- Hits 130967 128750 -2217
- Misses 36233 37132 +899
- Partials 3818 3881 +63
🚀 New features to boost your workflow:
|
Contributor
Author
|
/request-review @hubcio |
Contributor
Author
|
/request-review @numinnex |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Which issue does this PR address?
Related: #3694
Rationale
Without a declared minimum, every hook script has to be written against bash 3.2 and carry portable fallbacks (#3694). Checking the version once, up front, means anyone writing a hook script from now on can use modern bash without thinking about it.
What changed?
scripts/ci/lib/init.shchecks for bash >= 4.2 and is sourced by the 13 script-backed hooks, so a future check reaches all of them from one place.#!/bin/bashare normalized to#!/usr/bin/env bashfirst, since on macOS the former is always the system bash 3.2 and nobrew install bashcan override it.Local Execution
AI Usage
If AI tools were used, please answer: