Skip to content

Commit ac2b2ac

Browse files
committed
GitignoreParser._iter_gitignore_files: Account for ValueError in relpath
Fixes #1317
1 parent 4e971a6 commit ac2b2ac

2 files changed

Lines changed: 7 additions & 1 deletion

File tree

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@ Status of the `main` branch. Changes prior to the next official version change w
55
* General:
66
- Support environment variable `SERENA_USAGE_REPORTING` (set to `false` to disable usage reporting)
77
- Extended the list of always ignored directories (by language servers) with common cases.
8+
- Fix: When scanning for `.gitignore` files, the presence of files that could not be made relative
9+
to the project root would cause the scan to fail. #1317
810

911
JetBrains:
1012
- Improve handling of `relative_path` parameter

src/serena/util/file_system.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -177,7 +177,11 @@ def scan(abs_path: str | None) -> Iterator[str]:
177177
while queue:
178178
next_abs_path = queue.pop(0)
179179
if next_abs_path != self.repo_root:
180-
rel_path = os.path.relpath(next_abs_path, self.repo_root)
180+
try:
181+
rel_path = os.path.relpath(next_abs_path, self.repo_root)
182+
except ValueError:
183+
# If the path is on a different drive (Windows) or cannot be made relative for another reason, we ignore it
184+
continue
181185
if self.should_ignore(rel_path):
182186
continue
183187
yield from scan(next_abs_path)

0 commit comments

Comments
 (0)