From 36c1015442bd286337dd3ae4420a6fc767d06ed2 Mon Sep 17 00:00:00 2001 From: Joey Vagedes Date: Tue, 24 Oct 2023 15:23:54 -0700 Subject: [PATCH] Temp update --- edk2toollib/gitignore_parser.py | 7 +++++-- tests.unit/parsers/test_gitingore_parser.py | 8 +++++--- 2 files changed, 10 insertions(+), 5 deletions(-) diff --git a/edk2toollib/gitignore_parser.py b/edk2toollib/gitignore_parser.py index d0324ac7..0464a97e 100644 --- a/edk2toollib/gitignore_parser.py +++ b/edk2toollib/gitignore_parser.py @@ -5,6 +5,7 @@ import collections import os import re +import sys from os.path import abspath, dirname from pathlib import Path from typing import Union @@ -182,7 +183,8 @@ def match(self, abs_path): else: rel_path = str(_normalize_path(abs_path)) - rel_path += " " * _count_trailing_whitespace(abs_path) + if sys.platform.startswith('win'): + rel_path += " " * _count_trailing_whitespace(abs_path) # Path() strips the trailing slash, so we need to preserve it # in case of directory-only negation if self.negation and isinstance(abs_path, str) and abs_path[-1] == '/': @@ -279,4 +281,5 @@ def _count_trailing_whitespace(text: str): if char.isspace(): count += 1 else: - return count + break + return count diff --git a/tests.unit/parsers/test_gitingore_parser.py b/tests.unit/parsers/test_gitingore_parser.py index 9e66dad5..a3c6e688 100644 --- a/tests.unit/parsers/test_gitingore_parser.py +++ b/tests.unit/parsers/test_gitingore_parser.py @@ -296,7 +296,9 @@ def test_symlink_to_another_directory(): This test ensures that the issue is now fixed. """ with tempfile.TemporaryDirectory() as project_dir, tempfile.TemporaryDirectory() as another_dir: - gitignore_path = Path(project_dir, ".gitignore") + project_dir = Path(project_dir).resolve() + another_dir = Path(another_dir).resolve() + gitignore_path = project_dir / ".gitignore" with open(gitignore_path, 'w') as f: f.write('link\n') @@ -304,8 +306,8 @@ def test_symlink_to_another_directory(): rule_tester = gitignore_parser.parse_gitignore_file(gitignore_path, base_dir=project_dir) # Create a symlink to another directory. - link = Path(project_dir, 'link') - target = Path(another_dir, 'target') + link = project_dir / 'link' + target = another_dir / 'target' try: link.symlink_to(target) except OSError: # Missing permissions to do a symlink