Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ dependencies = [
"einops>=0.8.2",
"typer>=0.9.0",
"msgspec>=0.19.0",
"pathspec>=0.12.1",
"pathspec>=0.12.1,<1.0",
"pyyaml>=6.0",
"questionary>=2.0.0",
]
Expand Down
41 changes: 41 additions & 0 deletions tests/test_file_walk.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
"""Tests for shared source-file walking and gitignore filtering."""

from pathlib import Path

from cocoindex_code.file_walk import build_matcher, iter_included_files


def test_inverted_gitignore_keeps_source_directories_traversable(tmp_path: Path) -> None:
"""An ignore-all file can reopen directories and selected source extensions."""
(tmp_path / ".gitignore").write_text(
"\n".join(
[
"*",
"!*/",
"!*.cpp",
"!*.h",
"Content/",
"",
]
)
)

files = {
"Root.cpp": "int root;\n",
"Engine/Source/kept.cpp": "int kept;\n",
"Engine/Source/kept.h": "#pragma once\n",
"Engine/Source/ignored.bin": "generated\n",
"Content/reignored.cpp": "int generated;\n",
}
for relative_path, contents in files.items():
path = tmp_path / relative_path
path.parent.mkdir(parents=True, exist_ok=True)
path.write_text(contents)

matcher = build_matcher(tmp_path, ["**/*.cpp", "**/*.h"], [])
included = {
relative_path.as_posix()
for _, relative_path in iter_included_files(tmp_path, tmp_path, matcher)
}

assert included == {"Root.cpp", "Engine/Source/kept.cpp", "Engine/Source/kept.h"}
8 changes: 4 additions & 4 deletions uv.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading