GitignoreParser.should_ignore: Always ignore paths outside of the repository root #330

This commit is contained in:
Dominik Jain authored and Dominik Jain committed 2025-07-23 15:57:06 +02:00
1 parent aa52c6cfe0
commit f2b01a0573
1 file changed
+10 -1
+10 -1
View File
@@ -1,4 +1,5 @@
import glob
import logging
import os
from collections.abc import Callable
from dataclasses import dataclass, field
@@ -7,6 +8,8 @@ from typing import NamedTuple
import pathspec
from pathspec import PathSpec
log = logging.getLogger(__name__)
class ScanResult(NamedTuple):
"""Result of scanning a directory."""
@@ -243,7 +246,13 @@ class GitignoreParser:
"""
# Convert to relative path from repo root
if os.path.isabs(path):
rel_path = os.path.relpath(path, self.repo_root)
try:
rel_path = os.path.relpath(path, self.repo_root)
except Exception as e:
# If the path could not be converted to a relative path,
# it is outside the repository root, so we ignore it
log.info("Ignoring path '%s' which is outside of the repository root (%s)", path, e)
return True
else:
rel_path = path