mirror of
https://github.com/cyclotruc/gitingest.git
synced 2026-04-26 15:30:41 +00:00
Some checks failed
CI / test (macos-latest, 3.10) (push) Has been cancelled
CI / test (macos-latest, 3.11) (push) Has been cancelled
CI / test (macos-latest, 3.12) (push) Has been cancelled
CI / test (macos-latest, 3.13) (push) Has been cancelled
CI / test (macos-latest, 3.8) (push) Has been cancelled
CI / test (macos-latest, 3.9) (push) Has been cancelled
CI / test (ubuntu-latest, 3.10) (push) Has been cancelled
CI / test (ubuntu-latest, 3.11) (push) Has been cancelled
CI / test (ubuntu-latest, 3.12) (push) Has been cancelled
CI / test (ubuntu-latest, 3.13) (push) Has been cancelled
CI / test (ubuntu-latest, 3.8) (push) Has been cancelled
CI / test (ubuntu-latest, 3.9) (push) Has been cancelled
CI / test (windows-latest, 3.10) (push) Has been cancelled
CI / test (windows-latest, 3.11) (push) Has been cancelled
CI / test (windows-latest, 3.12) (push) Has been cancelled
CI / test (windows-latest, 3.13) (push) Has been cancelled
CI / test (windows-latest, 3.8) (push) Has been cancelled
CI / test (windows-latest, 3.9) (push) Has been cancelled
OSSF Scorecard / Scorecard analysis (push) Has been cancelled
* **Pre-commit**: replace `black` & `darglint` with `ruff-check` / `ruff-format`; add `pydoclint` for docstring quality * **Deps**: drop `tomli`; tighten `typing_extensions`; add `eval-type-backport`; remove `black`, `djlint`, `pylint` from `requirements-dev` * **Ignore files**: deprecate TOML-based `.gitingest`; introduce `.gitingestignore` (git-wildmatch, parsed via `_parse_ignore_file`) * **Config**: new unified `[tool.ruff]` (lint + format + isort); delete `[tool.black]`, keep minimal `[tool.isort]` for now * **Refactor/style**: adopt `from __future__ import annotations`, kw-only args, richer types; reorder params & `__all__`; move type-only imports under `if TYPE_CHECKING`; extract `_CLIArgs` `TypedDict`, migrate form data to `pydantic.QueryForm`; deduplicate `cli.main` / `_async_main`; use `pathlib`, avoid file-IO in async; replace magic numbers with constants; delete `is_text_file` (logic now lives in `FileSystemNode.content`) * **Bug fix**: remove silent error in `notebook_utils._process_cell` * **Docs**: refresh README badges * **Tests**: update fixtures & assertions **BREAKING**: new `.gitingestignore` file replaces (now-deprecated) `.gitingest`. No functional API or CLI changes.
69 lines
2.7 KiB
Python
69 lines
2.7 KiB
Python
"""Tests for the gitignore functionality in Gitingest."""
|
|
|
|
from pathlib import Path
|
|
|
|
import pytest
|
|
|
|
from gitingest.entrypoint import ingest_async
|
|
from gitingest.utils.ignore_patterns import load_ignore_patterns
|
|
|
|
|
|
@pytest.fixture(name="repo_path")
|
|
def repo_fixture(tmp_path: Path) -> Path:
|
|
"""Create a temporary repository structure.
|
|
|
|
The repository structure includes:
|
|
- A ``.gitignore`` that excludes ``exclude.txt``
|
|
- ``include.txt`` (should be processed)
|
|
- ``exclude.txt`` (should be skipped when gitignore rules are respected)
|
|
"""
|
|
# Create a .gitignore file that excludes 'exclude.txt'
|
|
gitignore_file = tmp_path / ".gitignore"
|
|
gitignore_file.write_text("exclude.txt\n")
|
|
|
|
# Create a file that should be included
|
|
include_file = tmp_path / "include.txt"
|
|
include_file.write_text("This file should be included.")
|
|
|
|
# Create a file that should be excluded
|
|
exclude_file = tmp_path / "exclude.txt"
|
|
exclude_file.write_text("This file should be excluded.")
|
|
|
|
return tmp_path
|
|
|
|
|
|
def test_load_gitignore_patterns(tmp_path: Path) -> None:
|
|
"""Test that ``load_ignore_patterns()`` correctly loads patterns from a ``.gitignore`` file."""
|
|
gitignore = tmp_path / ".gitignore"
|
|
# Write some sample patterns with a comment line included
|
|
gitignore.write_text("exclude.txt\n*.log\n# a comment\n")
|
|
|
|
patterns = load_ignore_patterns(tmp_path, filename=".gitignore")
|
|
|
|
# Check that the expected patterns are loaded
|
|
assert "exclude.txt" in patterns
|
|
assert "*.log" in patterns
|
|
# Ensure that comment lines are not added
|
|
for pattern in patterns:
|
|
assert not pattern.startswith("#")
|
|
|
|
|
|
@pytest.mark.asyncio
|
|
async def test_ingest_with_gitignore(repo_path: Path) -> None:
|
|
"""Integration test for ``ingest_async()`` respecting ``.gitignore`` rules.
|
|
|
|
When ``include_gitignored`` is ``False`` (default), the content of ``exclude.txt`` should be omitted.
|
|
When ``include_gitignored`` is ``True``, both files should be present.
|
|
"""
|
|
# Run ingestion with the gitignore functionality enabled.
|
|
_, _, content_with_ignore = await ingest_async(source=str(repo_path))
|
|
# 'exclude.txt' should be skipped.
|
|
assert "This file should be excluded." not in content_with_ignore
|
|
# 'include.txt' should be processed.
|
|
assert "This file should be included." in content_with_ignore
|
|
|
|
# Run ingestion with the gitignore functionality disabled.
|
|
_, _, content_without_ignore = await ingest_async(source=str(repo_path), include_gitignored=True)
|
|
# Now both files should be present.
|
|
assert "This file should be excluded." in content_without_ignore
|
|
assert "This file should be included." in content_without_ignore
|