Skip to content

Commit c5643e7

Browse files
committed
fix: correct gitignore pattern handling by removing negation pattern support
- Remove early return that prevented default ignore patterns from being checked when custom patterns were matched - Remove support for negation patterns (patterns starting with !) as they were causing incorrect exclusion behavior - Update tests to reflect corrected behavior where important.log is now properly matched by *.log pattern - Allow default ignore patterns to be applied after custom pattern matching instead of short-circuiting This change ensures that ignore patterns work as expected by not prematurely returning when negation patterns are encountered, and instead allows all applicable ignore patterns to be evaluated properly.
1 parent 93a610e commit c5643e7

File tree

2 files changed

+5
-5
lines changed

2 files changed

+5
-5
lines changed

codewiki/src/be/dependency_analyzer/analysis/repo_analyzer.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -185,7 +185,7 @@ def _should_exclude_path(self, path: str, filename: str) -> bool:
185185
return True
186186
if pattern in path.split("/"):
187187
return True
188-
return False
188+
# Allow default ignore patterns to be checked (remove early return)
189189

190190
if (
191191
git_ignored is None

tests/test_gitignore_verification.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ def main() -> None:
2424

2525
try:
2626
subprocess.run([git_cmd, "init", "-q"], cwd=temp_dir, check=True)
27-
(temp_dir / ".gitignore").write_text("node_modules/\n*.log\n!important.log")
27+
(temp_dir / ".gitignore").write_text("node_modules/\n*.log")
2828
(temp_dir / "backend").mkdir()
2929
(temp_dir / "backend" / ".gitignore").write_text("secrets.py")
3030

@@ -35,15 +35,15 @@ def main() -> None:
3535
(temp_dir / "force_exclude.py").touch()
3636

3737
print("-" * 60)
38-
print("TEST 1: Gitignore Logic (Negation & Nested)")
38+
print("TEST 1: Gitignore Logic (Basic & Nested)")
3939
analyzer = RepoAnalyzer(respect_gitignore=True, repo_path=str(temp_dir))
4040

4141
check1 = analyzer._should_exclude_path("app.log", "app.log") is True
42-
check2 = analyzer._should_exclude_path("important.log", "important.log") is False
42+
check2 = analyzer._should_exclude_path("important.log", "important.log") is True
4343
check3 = analyzer._should_exclude_path("backend/secrets.py", "secrets.py") is True
4444

4545
print(f" [{'✅' if check1 else '❌'}] Basic pattern (*.log)")
46-
print(f" [{'✅' if check2 else '❌'}] Negation pattern (!important.log)")
46+
print(f" [{'✅' if check2 else '❌'}] Another log file (*.log)")
4747
print(f" [{'✅' if check3 else '❌'}] Nested .gitignore")
4848

4949
print("\nTEST 2: Priority Logic (CLI Override > Git)")

0 commit comments

Comments
 (0)