Skip to content

Commit b322cfc

Browse files
committed
Allow recursive file globs to match root
1 parent e4d502d commit b322cfc

File tree

2 files changed

+9
-2
lines changed

2 files changed

+9
-2
lines changed

src/dir2md/core.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -70,9 +70,13 @@ def _pattern_allows_root_file(pattern: str) -> bool:
7070
while normalized.startswith('**/'):
7171
consumed_recursive = True
7272
normalized = normalized[3:]
73-
if consumed_recursive:
73+
if not normalized:
7474
return False
75-
return '/' not in normalized
75+
if '/' not in normalized:
76+
if consumed_recursive and '*' in normalized:
77+
return False
78+
return True
79+
return False
7680

7781

7882
def _expand_glob_patterns(patterns: List[str]) -> list[str]:

tests/test_dir2md.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -380,6 +380,9 @@ def run_config(include: list[str] | None = None, exclude: list[str] | None = Non
380380
include_src = run_config(include=["src/**/*.py"], suffix="include_src")
381381
assert include_src == {"src/utils/helper.py"}
382382

383+
include_recursive_root = run_config(include=["**/main.py"], suffix="include_recursive_root")
384+
assert include_recursive_root == {"main.py"}
385+
383386
exclude_pyc = run_config(exclude=["**/*.pyc"], suffix="exclude_pyc")
384387
assert "__pycache__/helper.cpython-39.pyc" not in exclude_pyc
385388
assert "src/__pycache__/main.cpython-39.pyc" not in exclude_pyc

0 commit comments

Comments
 (0)