|
23 | 23 | # the Free Software Foundation, 51 Franklin Street, Fifth Floor, |
24 | 24 | # Boston, MA 02110-1301, USA. |
25 | 25 |
|
| 26 | +from pathlib import Path |
| 27 | + |
26 | 28 | import pytest |
27 | 29 |
|
| 30 | +import pygit2 |
28 | 31 | from pygit2 import Repository |
29 | 32 | from pygit2.enums import FileStatus |
30 | 33 |
|
@@ -85,3 +88,39 @@ def test_status_ignored( |
85 | 88 | assert { |
86 | 89 | file for file, status in git_status.items() if status & FileStatus.IGNORED |
87 | 90 | } == 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