From f2b01a05738d6910abd233a98fe391747c97feaa Mon Sep 17 00:00:00 2001 From: Dominik Jain Date: Wed, 23 Jul 2025 15:56:17 +0200 Subject: [PATCH] GitignoreParser.should_ignore: Always ignore paths outside of the repository root #330 --- src/serena/util/file_system.py | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/src/serena/util/file_system.py b/src/serena/util/file_system.py index 26a59438..e4195aec 100644 --- a/src/serena/util/file_system.py +++ b/src/serena/util/file_system.py @@ -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