Skip to content

Commit 9ea4b37

Browse files
fix(ingest): validate single file existence against git reference
1 parent 4e259a0 commit 9ea4b37

File tree

1 file changed

+12
-0
lines changed

1 file changed

+12
-0
lines changed

src/gitingest/ingestion.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,18 @@ def ingest_query(query: IngestionQuery) -> tuple[str, str, str]:
6767
logger.error("Expected file but found non-file", extra={"path": str(path)})
6868
msg = f"Path {path} is not a file"
6969
raise ValueError(msg)
70+
71+
if query.url:
72+
from gitingest.utils.git_utils import create_git_repo
73+
repo = create_git_repo(str(query.local_path), query.url)
74+
75+
try:
76+
# Verify the path exists in the specific Git reference
77+
rev_path = f"{query.commit or query.branch or 'HEAD'}:{query.subpath.lstrip('/')}"
78+
repo.git.rev_parse("--verify", rev_path)
79+
except Exception as exc:
80+
msg = f"File '{query.subpath}' not found in the requested Git reference."
81+
raise ValueError(msg) from exc
7082

7183
relative_path = path.relative_to(query.local_path)
7284

0 commit comments

Comments
 (0)