Skip to content

Commit 89c4fa0

Browse files
committed
tests: add regression tests for status_file with non-ASCII paths
Cover paths with accented characters, non-breaking space, and both NFC/NFD normalization forms. Related to #687 Assisted-by: Kimi Code
1 parent c6da9eb commit 89c4fa0

1 file changed

Lines changed: 39 additions & 0 deletions

File tree

test/test_status.py

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,11 @@
2323
# the Free Software Foundation, 51 Franklin Street, Fifth Floor,
2424
# Boston, MA 02110-1301, USA.
2525

26+
from pathlib import Path
27+
2628
import pytest
2729

30+
import pygit2
2831
from pygit2 import Repository
2932
from pygit2.enums import FileStatus
3033

@@ -85,3 +88,39 @@ def test_status_ignored(
8588
assert {
8689
file for file, status in git_status.items() if status & FileStatus.IGNORED
8790
} == expected
91+
92+
93+
def test_status_file_non_ascii(tmp_path: Path) -> None:
94+
"""status_file must round-trip non-ASCII path names."""
95+
repo = pygit2.init_repository(str(tmp_path / 'repo'))
96+
path = 'täst_é.txt'
97+
(Path(repo.workdir) / path).write_text('hello')
98+
repo.index.add(path)
99+
repo.index.write()
100+
assert repo.status_file(path) == FileStatus.INDEX_NEW
101+
102+
103+
def test_status_file_non_breaking_space(tmp_path: Path) -> None:
104+
"""status_file must handle U+00A0 in the path."""
105+
repo = pygit2.init_repository(str(tmp_path / 'repo'))
106+
path = 'file\u00a0name.txt'
107+
(Path(repo.workdir) / path).write_text('hello')
108+
repo.index.add(path)
109+
repo.index.write()
110+
assert repo.status_file(path) == FileStatus.INDEX_NEW
111+
112+
113+
@pytest.mark.parametrize(
114+
'path',
115+
[
116+
'café.txt', # NFC
117+
'cafe\u0301.txt', # NFD
118+
],
119+
)
120+
def test_status_file_unicode_normalization(tmp_path: Path, path: str) -> None:
121+
"""status_file must work for both NFC and NFD forms of a path."""
122+
repo = pygit2.init_repository(str(tmp_path / 'repo'))
123+
(Path(repo.workdir) / path).write_text('hello')
124+
repo.index.add(path)
125+
repo.index.write()
126+
assert repo.status_file(path) == FileStatus.INDEX_NEW

0 commit comments

Comments
 (0)