FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

fix(index): accept a single PathLike in checkout by kokotatan · Pull Request #2269 · gitpython-developers/GitPython · GitHub

Repository navigation

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension .py  (2) All 1 file type selected
Viewed files
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Unified
Split
Hide whitespace
Diff view
Unified
Split
Hide whitespace
4 changes: 2 additions & 2 deletions git/index/base.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
Expand Up @@ -1303,7 +1303,7 @@ def _flush_stdin_and_wait(self, proc: "Popen[bytes]", ignore_stdout: bool = Fals
@default_index
def checkout(
self,
paths: Union[None, Iterable[PathLike]] = None,
paths: Union[None, PathLike, Iterable[PathLike]] = None,
force: bool = False,
fprogress: Callable = lambda *args: None,
allow_unsafe_options: bool = False,
Expand Down Expand Up @@ -1442,7 +1442,7 @@ def handle_stderr(proc: "Popen[bytes]", iter_checked_out_files: Iterable[PathLik
handle_stderr(proc, rval_iter)
return rval_iter
else:
if isinstance(paths, str):
if isinstance(paths, (str, os.PathLike)):
paths = [paths]

# Make sure we have our entries loaded before we start checkout_index, which
Expand Down
26 changes: 26 additions & 0 deletions test/test_index.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
Expand Up @@ -1731,6 +1731,32 @@ def test_index_file_v3_with_git_command(self, tmp_dir):
assert "A file2.txt" in status_lines


class TestIndexCheckout:
@pytest.mark.parametrize("path_type", [str, Path, PathLikeMock])
@pytest.mark.parametrize("absolute", [False, True])
@pytest.mark.parametrize("directory", [False, True])
@pytest.mark.parametrize("container", ["single", "list", "iterator"])
def test_checkout_pathlike(self, tmp_path, path_type, absolute, directory, container):
with Repo.init(tmp_path) as repo:
nested = tmp_path / "nested"
nested.mkdir()
files = {"nested/first": b"first", "nested/second": b"second", "outside": b"outside"}
for name, data in files.items():
(tmp_path / name).write_bytes(data)
repo.index.add(list(files))

path_name = "nested" if directory else "nested/first"
path = path_type(str(tmp_path / path_name) if absolute else path_name)
paths = path if container == "single" else [path] if container == "list" else iter([path])
expected = {"nested/first", "nested/second"} if directory else {"nested/first"}
for name in expected:
(tmp_path / name).unlink()

assert set(repo.index.checkout(paths)) == expected
for name, data in files.items():
assert (tmp_path / name).read_bytes() == data


class TestIndexUtils:
@pytest.mark.parametrize("file_path_type", [str, Path])
def test_temporary_file_swap(self, tmp_path, file_path_type):
Expand Down
Loading

Back | FazBrowse Home | New Git URL