| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -1303,7 +1303,7 @@ def _flush_stdin_and_wait(self, proc: "Popen[bytes]", ignore_stdout: bool = Fals | |||
| 1303 | 1303 | @default_index | |
| 1304 | 1304 | def checkout( | |
| 1305 | 1305 | self, | |
| 1306 | - paths: Union[None, Iterable[PathLike]] = None, | ||
| 1306 | + paths: Union[None, PathLike, Iterable[PathLike]] = None, | ||
| 1307 | 1307 | force: bool = False, | |
| 1308 | 1308 | fprogress: Callable = lambda *args: None, | |
| 1309 | 1309 | allow_unsafe_options: bool = False, | |
@@ -1442,7 +1442,7 @@ def handle_stderr(proc: "Popen[bytes]", iter_checked_out_files: Iterable[PathLik | |||
| 1442 | 1442 | handle_stderr(proc, rval_iter) | |
| 1443 | 1443 | return rval_iter | |
| 1444 | 1444 | else: | |
| 1445 | - if isinstance(paths, str): | ||
| 1445 | + if isinstance(paths, (str, os.PathLike)): | ||
| 1446 | 1446 | paths = [paths] | |
| 1447 | 1447 | ||
| 1448 | 1448 | # Make sure we have our entries loaded before we start checkout_index, which | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -1731,6 +1731,32 @@ def test_index_file_v3_with_git_command(self, tmp_dir): | |||
| 1731 | 1731 | assert "A file2.txt" in status_lines | |
| 1732 | 1732 | ||
| 1733 | 1733 | ||
| 1734 | + class TestIndexCheckout: | ||
| 1735 | + @pytest.mark.parametrize("path_type", [str, Path, PathLikeMock]) | ||
| 1736 | + @pytest.mark.parametrize("absolute", [False, True]) | ||
| 1737 | + @pytest.mark.parametrize("directory", [False, True]) | ||
| 1738 | + @pytest.mark.parametrize("container", ["single", "list", "iterator"]) | ||
| 1739 | + def test_checkout_pathlike(self, tmp_path, path_type, absolute, directory, container): | ||
| 1740 | + with Repo.init(tmp_path) as repo: | ||
| 1741 | + nested = tmp_path / "nested" | ||
| 1742 | + nested.mkdir() | ||
| 1743 | + files = {"nested/first": b"first", "nested/second": b"second", "outside": b"outside"} | ||
| 1744 | + for name, data in files.items(): | ||
| 1745 | + (tmp_path / name).write_bytes(data) | ||
| 1746 | + repo.index.add(list(files)) | ||
| 1747 | + | ||
| 1748 | + path_name = "nested" if directory else "nested/first" | ||
| 1749 | + path = path_type(str(tmp_path / path_name) if absolute else path_name) | ||
| 1750 | + paths = path if container == "single" else [path] if container == "list" else iter([path]) | ||
| 1751 | + expected = {"nested/first", "nested/second"} if directory else {"nested/first"} | ||
| 1752 | + for name in expected: | ||
| 1753 | + (tmp_path / name).unlink() | ||
| 1754 | + | ||
| 1755 | + assert set(repo.index.checkout(paths)) == expected | ||
| 1756 | + for name, data in files.items(): | ||
| 1757 | + assert (tmp_path / name).read_bytes() == data | ||
| 1758 | + | ||
| 1759 | + | ||
| 1734 | 1760 | class TestIndexUtils: | |
| 1735 | 1761 | @pytest.mark.parametrize("file_path_type", [str, Path]) | |
| 1736 | 1762 | def test_temporary_file_swap(self, tmp_path, file_path_type): | |
| Back | FazBrowse Home | New Git URL |
0 commit comments