Skip to content

fix(copy): match root-level files for ** glob patterns on Bash 3.2#133

Merged
helizaga merged 1 commit intomainfrom
fix/copy-globstar-root-match
Feb 24, 2026
Merged

fix(copy): match root-level files for ** glob patterns on Bash 3.2#133
helizaga merged 1 commit intomainfrom
fix/copy-globstar-root-match

Conversation

@helizaga
Copy link
Collaborator

@helizaga helizaga commented Feb 23, 2026

Summary

  • Fixes **/.env* and similar glob patterns not matching root-level files on macOS (Bash 3.2 find fallback)
  • Adds empty-string guard to prevent cp "" failures when find returns no results

Root Cause

find -path doesn't treat ** as a recursive glob — it's just a wildcard. The pattern ./**/.env* requires a / before .env, so root-level ./.env never matches. Additionally, empty find results still fed one blank line to while read, causing cp "" to fail.

Fix

For **/-prefixed patterns, also run find . -maxdepth 1 -path "./$suffix" to catch root-level files. Uses -maxdepth 1 to avoid duplicates with the deep search.

Test plan

  • bats tests/copy_safety.bats — 4 new tests covering empty results, root-level, nested, and mixed matching
  • bats tests/ — full suite (276 tests) passes
  • ShellCheck clean

Closes #132

Summary by CodeRabbit

Release Notes

  • Bug Fixes

    • Enhanced file pattern matching to better cover nested and root-level files in fallback scenarios.
    • Added defensive checks to prevent processing of empty results.
  • Tests

    • Added comprehensive test coverage for fallback pattern matching scenarios.

The find -path fallback doesn't treat ** as a recursive glob, so
patterns like **/.env* never matched root-level files. Now also
searches with the suffix pattern at maxdepth 1 for **/-prefixed
patterns. Adds an empty-string guard to prevent cp "" failures
when find returns no results.

Closes #132
@helizaga helizaga requested a review from NatoBoram as a code owner February 23, 2026 23:57
@coderabbitai
Copy link

coderabbitai bot commented Feb 23, 2026

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Disabled knowledge base sources:

  • Linear integration is disabled

You can enable these sources in your CodeRabbit configuration.

📥 Commits

Reviewing files that changed from the base of the PR and between 60d3bf2 and 83775ea.

📒 Files selected for processing (2)
  • lib/copy.sh
  • tests/copy_safety.bats

Walkthrough

The changes enhance the Bash 3.2 fallback mechanism in the copy utility to correctly handle recursive ** glob patterns by computing file matches via find before the copy loop and adding defensive empty-line checks. Test coverage validates the fallback behavior across various pattern-matching scenarios.

Changes

Cohort / File(s) Summary
Bash Fallback Enhancement
lib/copy.sh
Adds find-based discovery for ** patterns with root-level matching, empty-line guards to skip blank entries, and result merging to include both root and nested matches in the copied set.
Fallback Test Coverage
tests/copy_safety.bats
New test group for Bash 3.2 fallback path validation, covering empty results, root-level matches, nested matches, and combined scenarios with patterns like **/.env* and **/CLAUDE.md.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Poem

🐰 With ** patterns now tamed on the Mac,
Root-level files answer the call,
No empty strings trip up the stack,
The fallback path conquers them all! 🎉

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately describes the main fix: enabling root-level file matching for ** glob patterns in the Bash 3.2 fallback path.
Linked Issues check ✅ Passed The pull request implements all required coding objectives from #132: adds root-level file matching for **-prefixed patterns via maxdepth-1 find and includes empty-string guards in the copy loop.
Out of Scope Changes check ✅ Passed All changes in lib/copy.sh and tests/copy_safety.bats are directly related to fixing the ** glob pattern matching issue; no out-of-scope modifications detected.
Docstring Coverage ✅ Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
  • 📝 Generate docstrings (stacked PR)
  • 📝 Generate docstrings (commit on current branch)
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch fix/copy-globstar-root-match

Comment @coderabbitai help to get the list of available commands and usage tips.

@helizaga helizaga merged commit c74f843 into main Feb 24, 2026
4 checks passed
@helizaga helizaga deleted the fix/copy-globstar-root-match branch February 24, 2026 03:01
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.

copy: ** glob patterns don't match root-level files on macOS (Bash 3.2 find fallback)

1 participant