From ac2b2ac1313398aa23769bd4984c24e4ec566d14 Mon Sep 17 00:00:00 2001 From: Dominik Jain Date: Tue, 14 Apr 2026 12:21:52 +0200 Subject: [PATCH] GitignoreParser._iter_gitignore_files: Account for ValueError in relpath Fixes #1317 --- CHANGELOG.md | 2 ++ src/serena/util/file_system.py | 6 +++++- 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 6c4842ce..4542aa56 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,6 +5,8 @@ Status of the `main` branch. Changes prior to the next official version change w * General: - Support environment variable `SERENA_USAGE_REPORTING` (set to `false` to disable usage reporting) - Extended the list of always ignored directories (by language servers) with common cases. + - Fix: When scanning for `.gitignore` files, the presence of files that could not be made relative + to the project root would cause the scan to fail. #1317 JetBrains: - Improve handling of `relative_path` parameter diff --git a/src/serena/util/file_system.py b/src/serena/util/file_system.py index 318cb571..8240653d 100644 --- a/src/serena/util/file_system.py +++ b/src/serena/util/file_system.py @@ -177,7 +177,11 @@ class GitignoreParser: while queue: next_abs_path = queue.pop(0) if next_abs_path != self.repo_root: - rel_path = os.path.relpath(next_abs_path, self.repo_root) + try: + rel_path = os.path.relpath(next_abs_path, self.repo_root) + except ValueError: + # If the path is on a different drive (Windows) or cannot be made relative for another reason, we ignore it + continue if self.should_ignore(rel_path): continue yield from scan(next_abs_path)