From 9ea4b3700e83d1c0342853e762ab3fc590eafee3 Mon Sep 17 00:00:00 2001 From: Samarth Saxena <63669049+RealCuppa@users.noreply.github.com> Date: Fri, 19 Dec 2025 20:30:51 +0530 Subject: [PATCH] fix(ingest): validate single file existence against git reference --- src/gitingest/ingestion.py | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/src/gitingest/ingestion.py b/src/gitingest/ingestion.py index 01a2c8f3..b4867a66 100644 --- a/src/gitingest/ingestion.py +++ b/src/gitingest/ingestion.py @@ -67,6 +67,18 @@ def ingest_query(query: IngestionQuery) -> tuple[str, str, str]: logger.error("Expected file but found non-file", extra={"path": str(path)}) msg = f"Path {path} is not a file" raise ValueError(msg) + + if query.url: + from gitingest.utils.git_utils import create_git_repo + repo = create_git_repo(str(query.local_path), query.url) + + try: + # Verify the path exists in the specific Git reference + rev_path = f"{query.commit or query.branch or 'HEAD'}:{query.subpath.lstrip('/')}" + repo.git.rev_parse("--verify", rev_path) + except Exception as exc: + msg = f"File '{query.subpath}' not found in the requested Git reference." + raise ValueError(msg) from exc relative_path = path.relative_to(query.local_path)