fix(hooks): use POSIX [[:space:]] in guard-git.sh grep patterns#1170
Conversation
PR #1146 fixed BSD sed portability by replacing \s with [[:space:]] in sed patterns, but the grep -qE patterns in the same file still used \s. \s is a vendor extension (GNU/BSD grep accept it in ERE mode) but is not POSIX ERE, so it can fail on stricter graps such as busybox in Alpine containers. Replace all occurrences with [[:space:]] for uniform POSIX compliance and consistency with the existing sed patterns. Closes #1157
|
Claude finished @carlos-alm's task —— View job PR Review CompleteRoot Cause AnalysisProblem Being Solved: The guard-git.sh hook uses Why This Approach: This is a legitimate portability fix, not a workaround. The PR correctly addresses the root cause by replacing non-portable regex syntax with POSIX-compliant equivalents. It follows the same pattern established in #1146 for sed patterns, ensuring uniform compliance across the entire file. Risk Assessment: ✅ LOW RISK - Pure compatibility improvement with no behavior change on existing systems. Phase AnalysisPhase 1: ✅ Root Cause - LEGITIMATE FIXThis addresses a real portability issue, not symptom masking. The Phase 2: ✅ Configuration Changes - NOT APPLICABLENo configuration files, linting rules, or test thresholds modified. This is purely a pattern syntax fix. Phase 3: ✅ Test Integrity - NOT APPLICABLENo test files modified or assertions weakened. Phase 4: ✅ Code Quality ReviewExcellent quality:
Key changes verified:
Phase 5: ✅ Backlog ComplianceBacklog Compliance
Critical ConcernsNone identified. This is a well-executed portability fix. Final Recommendation
Recommendation: Approve and merge. This fix ensures the guard-git.sh hook works reliably across all deployment environments. |
Greptile SummaryThis PR completes the POSIX portability cleanup of
Confidence Score: 5/5Safe to merge — purely mechanical substitution of non-POSIX shorthand with its portable equivalent, with no changes to matching logic. Every \s in grep -qE patterns has been replaced with [[:space:]], which is the correct POSIX ERE equivalent. The sed patterns were already using [[:space:]], and the remaining grep calls in detect_work_dir (lines 122, 128) were never using \s and are untouched. The test plan covers the full set of command patterns the hook guards. No behavioral change on BSD/GNU grep; the fix only matters on POSIX-strict grep implementations where \s was silently treated as literal s. No files require special attention. Important Files Changed
Reviews (2): Last reviewed commit: "Merge branch 'main' into fix/1157-guard-..." | Re-trigger Greptile |
Summary
\sshorthand with POSIX[[:space:]]in thegrep -qEpatterns of.claude/hooks/guard-git.sh.\sin ERE mode as a vendor extension, but it is not POSIX. Stricter graps (e.g. busybox in Alpine) treat the pattern literally and miss matches.Context
Follow-up to Greptile feedback on PR #1153, which was closed as superseded by #1146 before this suggestion could be addressed. Tracked in #1157.
No behavior change on macOS or stock Linux runners (BSD/GNU grep both keep matching). The fix only affects POSIX-strict environments where
\swas silently treated as a literals.Test plan
bash -n .claude/hooks/guard-git.sh— syntax checkgit add .,git add -A,git add --all,git reset,git restore --staged,git push,gh pr create,git commit,cd /tmp && git status, and tab-separated variants — all match as before;git add file.txtandecho hellostill no-match.Closes #1157