fix: avoid ignoring root path in gitignore checks

Fixes #1054

Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
zerone0xandClaude committed 2026-04-09 04:37:23 +02:00
1 parent ab38fa98f1
commit 1b299830fd
2 files changed
+13 -1

No files matched your search

+3
View File
@@ -341,6 +341,9 @@ def match_path(relative_path: str, path_spec: PathSpec, root_path: str = "") ->
:param root_path: the root path from which the relative path is derived
:return:
"""
if str(relative_path) in {"", "."}:
return False
normalized_path = str(relative_path).replace(os.path.sep, "/")
# We can have patterns like /src/..., which would only match corresponding paths from the repo root
+10 -1
View File
@@ -4,7 +4,9 @@ import tempfile
from pathlib import Path
# Assuming the gitignore parser code is in a module named 'gitignore_parser'
from serena.util.file_system import GitignoreParser, GitignoreSpec
from pathspec import PathSpec
from serena.util.file_system import GitignoreParser, GitignoreSpec, match_path
class TestGitignoreParser:
@@ -191,6 +193,13 @@ test.log
assert not parser.should_ignore("file1.txt")
assert not parser.should_ignore("src/main.py")
def test_match_path_root_directory(self):
"""Root directory should never be ignored by pathspec patterns."""
spec = PathSpec.from_lines("gitwildmatch", ["/.*/"])
assert not match_path(".", spec, root_path=str(self.repo_path))
assert not match_path("", spec, root_path=str(self.repo_path))
def test_should_ignore_subdirectory_patterns(self):
"""Test ignoring files based on subdirectory .gitignore files."""
parser = GitignoreParser(str(self.repo_path))