Skip to content

fix(hooks): make git-push-approval hook work with macOS Bash 3.2 - #222

Merged
DevSecNinja merged 2 commits into
mainfrom
devsecninja-fix-hook-bash32-compat
Nov 13, 2026
Merged

DevSecNinja merged 2 commits into
mainfrom
devsecninja-fix-hook-bash32-compat

Conversation

@DevSecNinja

Copy link
Copy Markdown
Owner

Closes #217

What

  • scripts/git-push-approval/require-push-approval.sh lowercased the tool name with ${1,,} (Bash 4). Stock macOS runs #!/bin/bash as Bash 3.2, where that's a bad substitution. It now lowercases with tr.
  • New tests/test_hook_scripts.py:
    • a static scan of every script referenced by .apm/hooks/*.json for Bash 4+ syntax (case modification, declare -A/-n, mapfile, |&, &>>, [[ -v ]], ${var@Q}, …);
    • behaviour checks for both hooks (mixed-case tool names, VS Code payload, non-push commands, SKIP_PUSH_APPROVAL, guard allow/block), run with $HOOK_BASH.
  • New Hook Scripts workflow runs that test with the runner's Bash, then again with a real Bash 3.2.57 built by tests/build-bash32.sh (pinned tarball SHA-256). EXPECT_BASH_VERSION=3.2 makes the run fail if it isn't 3.2.
  • scripts/tool-guardian/guard-tool.sh was checked: no Bash 4+ syntax, and it passes the behaviour tests under 3.2. No change needed.

Behaviour found while reproducing

Under a real Bash 3.2.57, the old hook printed bad substitution but exited 0 with no decision. So on macOS git push wasn't gated at all (the issue expected a fail-closed deny). The new behaviour tests catch both outcomes, because they require the ask JSON and exit 0.

Notes

Validation (separate tester contexts)

  • test_hook_scripts.py: 10/10 pass with Bash 5.2 and with Bash 3.2.57. The version assertion ran.
  • The old script reproduces bad substitution under 3.2, and the static scan flags its ${1,,} line.
  • shellcheck 0.11.0 and shfmt 3.14.1 report nothing. All lefthook pre-commit checks passed. The commit is signed.

require-push-approval.sh lowercased the tool name with `${1,,}`, a Bash 4
expansion. Stock macOS runs `#!/bin/bash` under Bash 3.2, where it is a
"bad substitution", so the hook never emitted its "ask" decision. Lowercase
with `tr` instead.

Add tests/test_hook_scripts.py: a static scan of every script referenced by
.apm/hooks/*.json for Bash 4+ syntax, plus behaviour checks for both hooks.
The new Hook Scripts workflow runs them with the runner's Bash and again
with a Bash 3.2.57 built by tests/build-bash32.sh.

Closes #217

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
@coderabbitai

coderabbitai Bot commented Nov 11, 2026 •

Copy link
Copy Markdown

Warning

Review limit reached

You've used all free OSS reviews for now. Wait for the free limit to reset to keep reviewing this public repository.

Next included review available in 43 minutes.

Check out review usage here.

View limit details

Limit details: You’ve used the included review currently available.

Learn how review limits work.

Review configuration:

Run configuration

  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: defaults
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: e28082c5-bb62-440d-89b5-5acb66189f90
Commits

Reviewing files that changed from the base of the PR and between a398c92 and d0428e4.

Files selected for processing: 4

  • .github/workflows/hook-scripts.yml
  • scripts/git-push-approval/require-push-approval.sh
  • tests/build-bash32.sh
  • tests/test_hook_scripts.py
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

Share

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Changes recommended

A relative destination is resolved inside the temporary build tree, causing the helper to delete the copied binary on exit while reporting success and a nonexistent output path.

1 open issue
What changed in this PR

This PR restores the git-push approval hook’s compatibility with stock macOS Bash 3.2 and adds regression checks for the shipped hooks, addressing #217.

Changes:

  • Replaces Bash 4-only lowercasing with portable tr.
  • Adds static compatibility scans and behavior tests for both hooks.
  • Adds a checksum-pinned Bash 3.2 build helper and a dedicated workflow testing both interpreter versions.
File Description
tests/​test_hook_scripts.py Adds compatibility scans, hook behavior tests, and interpreter version checks.
tests/​build-bash32.sh Builds checksum-verified Bash 3.2.57 for compatibility testing.
scripts/​git-push-approval/​require-push-approval.sh Uses Bash 3.2-compatible tool-name lowercasing.
.github/​workflows/​hook-scripts.yml Runs hook tests with the runner’s Bash and Bash 3.2.

Review effort: Balanced

Comment thread tests/build-bash32.sh Resolved
Resolve DEST against the caller's directory before the build changes into
the temporary source tree, so a relative destination isn't copied into the
tree the EXIT trap deletes.

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
@DevSecNinja
DevSecNinja merged commit 8b99a82 into main Nov 13, 2026
20 checks passed
@DevSecNinja
DevSecNinja deleted the devsecninja-fix-hook-bash32-compat branch November 13, 2026 10:47
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

fix(hooks): make git-push-approval hook work with macOS Bash 3.2

2 participants